You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
vite:esm-shim can corrupt Vite 8/Rolldown ESM main bundle and emit empty entry #906
With [email protected] and Vite 8/Rolldown, the injected vite:esm-shim plugin can corrupt an ESM main-process bundle and cause the main entry to be emitted as an empty file.
In our app, the Electron main build emits:
dist/main/index.js 0.00 kB
Removing only the vite:esm-shim plugin from the resolved main config makes the same build emit a valid bundle:
dist/main/index.js ~3.5 MB
Versions
electron-vite: 6.0.0-beta.1
vite: 8.0.13
electron: 42.1.0
node: 24.14.0 / Electron Node 24.15.0
package type: module
main output format: es
If it sees CommonJS-looking syntax, it tries to insert the shim after the last static import, using a regex over the fully rendered chunk.
In this app's generated main chunk, that static import regex matches import-looking text inside embedded string content, not a real top-level ESM import. I instrumented the shim and it selected this false match as the last import:
import{XxxModel,XxxOption}from'./XxxModel.js';
That match was around offset 2649169 in the rendered chunk. The shim was then inserted at that position, corrupting the chunk. Rolldown subsequently emitted the entry chunk as empty.
Relevant debug output
Instrumenting an equivalent shim plugin produced:
renderChunk index.js es 3498223 true
inject at 2649169 imports 60 last "import {XxxModel, XxxOption} from './XxxModel.js';"
rendering chunks...
bundle index.js 0
Expected behavior
The shim should not parse rendered JavaScript with a regex that can match import-like text inside strings/comments. It should either avoid this injection when safe globals already exist, use an AST-aware insertion strategy, or insert at a known safe position.
Workaround
We currently remove only vite:esm-shim from the resolved Electron main Vite config:
Activity
Hona commentedon Jul 4, 2026
I'm running into this too one OpenCode Desktop
fix: stabilize Vite 8/Rolldown beta and merge pending fixes
fix(esm-shim): ignore import-like text inside strings/comments
fix(esm-shim): ignore import-like text inside strings/comments
fix(esmShim)!: use `this.parse` to find the last static import (#906)
alex8088 commentedon Sep 28, 2026
6.0.0-beta.4 is out
alex8088 commentedon Oct 22, 2026
v6.0.0 is out
chore: sync upstream electron-vite v6.0.0 (35 commits), preserving fo…
Sync upstream electron-vite v6.0.0 (35 commits), preserving fork feat…