← All tasks
javascriptvitejs/vite #22750Not a task: not reproduced

Dev server corrupts a method named `import`, causing SyntaxError: Unexpected token '('

envgap__vitejs__vite-22750

01 / FAILURE SIGNATURE

As reported upstream

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.
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
c4acd6982a051fa10dbd7e3a37e00f0c467793b8
Manifest
packages/vite/package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

vitejs/vite #22750 · read the original issue
### 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:

```diff
- 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

1. Scaffold a vanilla app: `npm create vite@latest repro -- --template vanilla`
2. Add `src/foo.js` and import it from `src/main.js`.
3. `npm install && npm run dev`
4. Open the app.

The served module (Network tab, or `curl http://localhost:5173/src/foo.js`) contains the corrupted line:
```js
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

```shell
#  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

- [x] Follow our [Code of Conduct](https://github.com/vitejs/.github/blob/main/CODE_OF_CONDUCT.md)
- [x] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md).
- [x] Read the [docs](https://vite.dev/guide).
- [x] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
- [x] 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](https://github.com/vuejs/core) instead.
- [x] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vite.dev/).
- [x] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]