Repository navigation
Closed as duplicate
Labels
Description
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.jsUsed 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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
Reacted by Damien Daspit and AdaptivChris
Activity
Work around vitejs/vite#18582
Work around vitejs/vite#18582
nozomuikuta commentedon Jan 5, 2025
As far as I see, it seems that import attributes support is still under discussion: #18534, which would require changes on upstream bundler like Rollup (and Rolldown in future).
fix: hack around vite/node disagreeing on attributse
type: 'json'causes syntax error on Firefox #19095