fix(build): ship production node_modules in the asar#4462
Conversation
After the Vite v8 migration (b1c880f), electron-vite's default externalizeDeps: true strips most npm dependencies out of the main and preload bundles, leaving runtime require() calls (electron-store, electron-is, deepmerge-ts, i18next, and their transitive deps) that expect to find those packages in node_modules at runtime. The previous electron-builder config excluded node_modules from the asar ('!node_modules') and only whitelisted three packages. Every externalized require failed at runtime in packaged builds, with errors like: Error: Cannot find module 'electron-store' Error: Cannot find module 'electron-is' pnpm start (electron-vite preview) was unaffected because it serves the built code from the project tree where node_modules is intact. Only dist:* hit the failure. Drop the manual exclusion and let electron-builder ship production dependencies from package.json by default. The asar grows but every externalized require resolves.
📝 WalkthroughWalkthroughUpdated ChangesBuild packaging configuration
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
electron-builder.yml (1)
11-12: 💤 Low valueConsider excluding additional file types from node_modules.
To further reduce bundle size, you could exclude TypeScript declaration files and documentation:
- '!node_modules/**/*.map' - '!node_modules/**/*.ts' - '!node_modules/**/*.d.ts' - '!node_modules/**/README.md' - '!node_modules/**/CHANGELOG.md'This is optional and would provide marginal size savings.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@electron-builder.yml` around lines 11 - 12, Update the exclusion list in electron-builder.yml to also filter out TypeScript declaration files and common docs to shrink the packaged node_modules: add patterns like '!node_modules/**/*.d.ts', '!node_modules/**/README.md', and '!node_modules/**/CHANGELOG.md' alongside the existing '!node_modules/**/*.map' and '!node_modules/**/*.ts' entries so the packager excludes those files during build.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@electron-builder.yml`:
- Around line 11-12: Update the exclusion list in electron-builder.yml to also
filter out TypeScript declaration files and common docs to shrink the packaged
node_modules: add patterns like '!node_modules/**/*.d.ts',
'!node_modules/**/README.md', and '!node_modules/**/CHANGELOG.md' alongside the
existing '!node_modules/**/*.map' and '!node_modules/**/*.ts' entries so the
packager excludes those files during build.
Summary
After the Vite v8 migration (b1c880f), electron-vite's default
externalizeDeps: truestrips most npm dependencies out of the main and preload bundles, leaving runtimerequire()calls forelectron-store,electron-is,deepmerge-ts,i18next, and their transitive deps. The previouselectron-builder.ymlexcludednode_modulesfrom the asar with only a 3-package allowlist, so those requires failed at runtime in packaged builds.pnpm startworked because electron-vite preview serves the built code from the project tree. Onlypnpm dist:*produced the failure.Fix
Drop
!node_modulesand the manual allowlist; let electron-builder ship production deps frompackage.jsonby default. The asar grows by some MB but every externalizedrequireresolves.Closes #4446
Test plan
pnpm dist:winproduces a launchable build that opens past the renderer init phasepnpm start/pnpm devflowsSummary by CodeRabbit