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

vite:dynamic-import-vars #18582

Open
7 tasks done
SLaks opened this issue Nov 5, 2024 · 0 comments
Open
7 tasks done

vite:dynamic-import-vars #18582

SLaks opened this issue Nov 5, 2024 · 0 comments

Comments

@SLaks
Copy link

SLaks commented Nov 5, 2024

Describe the bug

await import(`./demo-${n}.json`, { with: { type: 'json' } });
[plugin:vite:dynamic-import-vars] [plugin vite:dynamic-import-vars] main.js: invalid import "./demo-${n}.json`, { with: { type: 'json' } ". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. For example: import(`./foo/${bar}.js`).

Removing the second parameter fixes the error, but breaks the import when run in Node.js.

For JSON imports in particular, this should be supported (just ignore the param, or verify that it is in fact JSON).

Reproduction

https://stackblitz.com/edit/vitejs-vite-gud6b7?file=main.js

Steps to reproduce

Run npm build, or just load the demo page

System Info

https://stackblitz.com/edit/vitejs-vite-gud6b7?file=main.js

Used Package Manager

npm

Logs

Click to expand!
[plugin:vite:dynamic-import-vars] [plugin vite:dynamic-import-vars] main.js: invalid import "./demo-${n}.json`, { with: { type: 'json' } ". It cannot be statically analyzed. Variable dynamic imports must start with ./ and be limited to a specific directory. For example: import(`./foo/${bar}.js`).
✓ 8 modules transformed.
dist/index.html                 0.45 kB │ gzip: 0.29 kB
dist/assets/index-DRNMkqs8.css  1.21 kB │ gzip: 0.63 kB
dist/assets/demo-1-CdeqYGsu.js  0.03 kB │ gzip: 0.05 kB
dist/assets/demo-2-B2seS4W8.js  0.03 kB │ gzip: 0.05 kB
dist/assets/index-o-WUo9bb.js   2.37 kB │ gzip: 1.19 kB
✓ built in 990ms

Validations

SLaks added a commit to SLaks/tikkun.io that referenced this issue Nov 5, 2024
After that issue is fixed, this commit should be reverted.
SLaks added a commit to SLaks/tikkun.io that referenced this issue Nov 5, 2024
After that issue is fixed, this commit should be reverted.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant