Skip to content

vite:dynamic-import-vars  #18582

Closed as duplicate
Closed as duplicate

Description

@SLaks

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

Activity

  1. nozomuikuta commented on Jan 5, 2025

    @nozomuikuta
    Contributor

    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).

  2. locked and limited conversation to collaborators on Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions