Skip to content

fix(build): ship production node_modules in the asar#4462

Open
emilichu wants to merge 1 commit into
pear-devs:masterfrom
emilichu:fix/electron-builder-include-node-modules
Open

fix(build): ship production node_modules in the asar#4462
emilichu wants to merge 1 commit into
pear-devs:masterfrom
emilichu:fix/electron-builder-include-node-modules

Conversation

@emilichu
Copy link
Copy Markdown

@emilichu emilichu commented May 15, 2026

Summary

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 for electron-store, electron-is, deepmerge-ts, i18next, and their transitive deps. The previous electron-builder.yml excluded node_modules from the asar with only a 3-package allowlist, so those requires failed at runtime in packaged builds.

pnpm start worked because electron-vite preview serves the built code from the project tree. Only pnpm dist:* produced the failure.

Fix

Drop !node_modules and the manual allowlist; let electron-builder ship production deps from package.json by default. The asar grows by some MB but every externalized require resolves.

Closes #4446

Test plan

  • pnpm dist:win produces a launchable build that opens past the renderer init phase
  • No regressions for pnpm start / pnpm dev flows

Summary by CodeRabbit

  • Chores
    • Refined application packaging configuration to adjust how production dependencies and build artifacts are included in distribution builds.

Review Change Stack

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.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 15, 2026

📝 Walkthrough

Walkthrough

Updated electron-builder.yml to simplify node_modules packaging rules. Removed explicit exclusion patterns for specific node_modules packages and added comments clarifying that production dependencies are included by default, with only source maps (**.map) and TypeScript files (**.ts) excluded.

Changes

Build packaging configuration

Layer / File(s) Summary
node_modules handling in packaging rules
electron-builder.yml
Removed explicit exclusion rules for specific node_modules packages and added clarifying comments that production dependencies are included by default while source maps and TypeScript files are trimmed via existing !node_modules/**/*.map and !node_modules/**/*.ts filters.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A builder once packed with great care,
Excluding each node_modules snare,
Now defaults run true,
With trimming just two:
Maps and TypeScript removed from the air! 📦✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: fixing the build process to include production node_modules in the asar package, which directly addresses the packaged build failures.
Linked Issues check ✅ Passed The PR directly resolves the linked issue #4446 by ensuring externalized dependencies like 'electron-is-accelerator' are included in the packaged asar, fixing runtime module resolution errors.
Out of Scope Changes check ✅ Passed The changes are limited to electron-builder.yml configuration for packaging production dependencies, directly addressing the scope of fixing packaged build failures without unrelated modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
electron-builder.yml (1)

11-12: 💤 Low value

Consider 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ad2ad8e3-ba0c-4c8e-9bee-04326d9e255b

📥 Commits

Reviewing files that changed from the base of the PR and between 9e7a2dd and 07ce031.

📒 Files selected for processing (1)
  • electron-builder.yml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: Cannot find module 'electron-is-accelerator'

1 participant