Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import error when using package imports in vite.config.js #18867

Closed
7 tasks done
geigerzaehler opened this issue Dec 3, 2024 · 3 comments · Fixed by #18887
Closed
7 tasks done

Import error when using package imports in vite.config.js #18867

geigerzaehler opened this issue Dec 3, 2024 · 3 comments · Fixed by #18887
Labels
p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release

Comments

@geigerzaehler
Copy link
Contributor

geigerzaehler commented Dec 3, 2024

Describe the bug

When I use package imports in vite.config.js, Vite fails to load the configuration file and displays the following error:

failed to load config from .../vite.config.js
error when starting dev server:
TypeError [ERR_PACKAGE_IMPORT_NOT_DEFINED]: Package import specifier "#src/utils.js" is not defined imported from .../node_modules/.vite-temp/vite.config.ts.timestamp-1733215455982-e048dc6e2c576.mjs

This used to work in v5. My best guess is that it is caused by #18509.

Reproduction

https://stackblitz.com/edit/stackblitz-starters-aszvug?file=package.json

Steps to reproduce

pnpm install
npx vite

System Info

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: ^6.0.2 => 6.0.2 

Used Package Manager

pnpm

Logs

No response

Validations

@bluwy bluwy added p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release and removed pending triage labels Dec 3, 2024
@bluwy
Copy link
Member

bluwy commented Dec 3, 2024

Looks like any files placed in node_modules can't access subpath imports from the root package.json, which is strange and I don't see it particularly documented in node. Anyways I guess we have to resolve subpath imports as well to fix this.

@lehni
Copy link

lehni commented Dec 3, 2024

It looks like #18637 would solve this since it doesn't rely on the temporary file inside node_modules anymore.

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Dec 4, 2024

Spec wise, probably Node bans this since LOOKUP_PACKAGE_SCOPE cuts off early for files under node_modules. I'm reading PACKAGE_IMPORTS_RESOLVE and LOOKUP_PACKAGE_SCOPE in https://nodejs.org/docs/v22.12.0/api/esm.html#resolution-algorithm-specification.

@github-actions github-actions bot locked and limited conversation to collaborators Dec 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p4-important Violate documented behavior or significantly improves performance (priority) regression The issue only appears after a new release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants