Describe the bug
In Vite 8.1.0, the dev server's importAnalysis transform mistakes a method or identifier named import (e.g. async import(keys, values) {} inside a class) for a dynamic import() expression. It injects the query-injection helper into the method's parameter list, producing invalid JavaScript:
- async import(keys, values) {
+ async import(__vite__injectQuery(keys, 'import'), values) {
A function/method parameter list cannot contain a call expression, so the browser throws SyntaxError: Unexpected token '(' when it loads the served module, and the app fails to mount.
This is dev-server only — vite build (production) is unaffected. import is a legal method name (class { import() {} }, obj.import()), so this is valid application code being corrupted by Vite. It regressed between 8.0.16 (OK) and 8.1.0 (broken).
Reproduction
https://stackblitz.com/edit/vitejs-vite-bztul6vj
Steps to reproduce
- Scaffold a vanilla app:
npm create vite@latest repro -- --template vanilla
- Add
src/foo.js and import it from src/main.js.
npm install && npm run dev
- Open the app.
The served module (Network tab, or curl http://localhost:5173/src/foo.js) contains the corrupted line:
async import(__vite__injectQuery(keys, 'import'), values) {
Downgrade confirms the regression (same app, same Node, only Vite changed):
| Vite |
Served output |
Result |
| 8.1.0 |
async import(__vite__injectQuery(keys, 'import'), values) |
SyntaxError |
| 8.0.16 |
async import(keys, values) |
OK |
Likely cause: es-module-lexer was bumped to 2.0.0 in 8.1.0. The dev-server import scanner appears to tokenize a bare import identifier/method as a dynamic-import keyword, and the query-injection rewrite then targets it. The rewrite should only apply to genuine dynamic import(...) call expressions, not to identifiers/methods named import.
System Info
# Key versions observed:
# vite 8.1.0 (regressed; last good: 8.0.16)
# es-module-lexer 2.0.0
# Node 24.17.0
Used Package Manager
npm
Logs
No response
Validations
Describe the bug
In Vite 8.1.0, the dev server's
importAnalysistransform mistakes a method or identifier namedimport(e.g.async import(keys, values) {}inside a class) for a dynamicimport()expression. It injects the query-injection helper into the method's parameter list, producing invalid JavaScript:A function/method parameter list cannot contain a call expression, so the browser throws
SyntaxError: Unexpected token '('when it loads the served module, and the app fails to mount.This is dev-server only —
vite build(production) is unaffected.importis a legal method name (class { import() {} },obj.import()), so this is valid application code being corrupted by Vite. It regressed between 8.0.16 (OK) and 8.1.0 (broken).Reproduction
https://stackblitz.com/edit/vitejs-vite-bztul6vj
Steps to reproduce
npm create vite@latest repro -- --template vanillasrc/foo.jsand import it fromsrc/main.js.npm install && npm run devThe served module (Network tab, or
curl http://localhost:5173/src/foo.js) contains the corrupted line:Downgrade confirms the regression (same app, same Node, only Vite changed):
async import(__vite__injectQuery(keys, 'import'), values)async import(keys, values)Likely cause:
es-module-lexerwas bumped to2.0.0in 8.1.0. The dev-server import scanner appears to tokenize a bareimportidentifier/method as a dynamic-import keyword, and the query-injection rewrite then targets it. The rewrite should only apply to genuine dynamicimport(...)call expressions, not to identifiers/methods namedimport.System Info
Used Package Manager
npm
Logs
No response
Validations