Skip to content

[Vite 8] dynamic import bug: comments break dynamicImportVarsPlugin #21855

@dake3601

Description

@dake3601

Describe the bug

Bug

A comment inside a dynamic import() with a template literal prevents Vite 8's dynamicImportVarsPlugin from transforming it into a static glob map.

// BROKEN — import is left untransformed, matching files are not bundled
const strings = await import(/* strings */ `./translations/${locale}/strings.json`);

// WORKS — transformed into a static Object.assign map with all matching files
const strings = await import(`./translations/${locale}/strings.json`);

These comments are harmless in Vite 7 (Rollup and Rolldown) but break dynamic import resolution in Vite 8 (Rolldown).

Expected behavior

Both forms should produce identical output.

Reproduce

npm install
npm run build

Inspect dist/assets/index-*.js:

  • With comment: the import() passes through untransformed — no translation chunks are emitted.
  • Without comment: dynamicImportVarsPlugin produces the expected static map and separate chunks for each translation file.

Reproduction

https://github.com/dake3601/vite-dynamic-import-repro

Steps to reproduce

Run npm install followed by npm run build

To see it working correctly remove the comment inside the import at main.js

System Info

System:
  OS: Windows 11
Binaries:
  Node: 24.13.0
  npm: 11.6.2
npmPackages:
  vite: ^8.0.0 => 8.0.0

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

Labels

clarity: highinconsistencyInconsistency between dev & buildp4-importantViolate documented behavior or significantly improves performance (priority)

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions