Back to all fixes
CuratedTypeScriptVite 8local
Vite 8.1.0 dev server: "Uncaught (in promise) SyntaxError: Unexpected token '('" from a class method named `import`
Problem
Blank page in dev only (production build unaffected) after upgrading to Vite 8.1.0, caused by any dependency that has a class method literally named `import(...)` (e.g. TensorFlow.js's HashTable.import, @polymer/polymer's DomModule.import, pocketbase JS SDK's CollectionService.import). Vite's import-analysis mistakes the method call for a dynamic import and rewrites it into invalid JS: `async import(__vite__injectQuery(keys, 'import'), values) { ... }`.
Solution
typescript
Root cause is an es-module-lexer 2.0 regression (upstream bug, fixed in es-module-lexer 2.2.0, see guybedford/es-module-lexer#208). The Vite-side bump to pick up that fix was later reverted (PR #22827) and the issue was reopened, so do not assume a specific Vite patch version alone fixes this - check current release notes. Until confirmed fixed in your installed version, pin/override to the last known-good release:
```yaml
# pnpm-workspace.yaml
overrides:
vite: 8.0.16
```
If you cannot pin (e.g. transitive dependency forces the version), a dev-only Vite plugin can patch the served pre-bundled files to undo the bogus rewrite via a middleware regex replace on `/deps/*.js` responses matching `import\(__vite__injectQuery\(([^,)]+),\s*'import'\),`.