Fix packaged app crashing on launch (Cannot find module) - #32
Conversation
The released builds crashed the moment the main process started, with "Cannot find module 'zod'". Root cause: the electron-forge Vite template marks every production dependency as external, so main.js require()s them at runtime, but the packaged app.asar ships no node_modules at all (only the .vite build output and package.json). The first external require therefore fails and takes down the app before any window appears. Fix: bundle the dependencies into the main and preload output instead of externalising them. The main and preload processes use no native modules, so this is safe and makes the packaged app self-contained. Only Electron, Node builtins, and ws's optional native addons (bufferutil, utf-8-validate, which ws requires in a try/catch) stay external. electron-squirrel-startup was a second straggler: it was loaded via a raw require() call, which stays external even when bundling, so it became the next crash. Import it instead so it is bundled, with a local type declaration since it ships no types. Verified by building an actual package and launching it: both windows render and there are no module errors, which dev-mode testing (npm start, which resolves node_modules directly) could never have caught. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedReview was skipped due to path filters ⛔ Files ignored due to path filters (1)
CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe package version changes to 0.20.1. The main process uses a static, typed ChangesApplication Packaging
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@package.json`:
- Line 5: Update both root version metadata entries in package-lock.json from
0.18.0 to 0.20.1, matching the package.json version while leaving dependency
contents unchanged.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 3ab9c02c-add8-4155-b47d-d21b18ebbf09
📒 Files selected for processing (4)
package.jsonsrc/main.tssrc/types/electron-squirrel-startup.d.tsvite.base.config.ts
The lockfile's root version fields had drifted to 0.18.0 (manual version bumps did not update them). Regenerated with --package-lock-only, which updates only the two version fields and leaves the dependency tree unchanged. Addresses the CodeRabbit comment on this PR. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fixes the released app crashing on launch
Your dad's v0.20.0 (and in fact every recent release) crashes the instant it opens, with:
Root cause
The electron-forge Vite template marks every production dependency as external, so the compiled
main.jsdoesrequire('zod')(and every other dep) at runtime. But the packagedapp.asarships nonode_modulesat all, only the.vitebuild output andpackage.json. So the first external require fails and takes the app down before any window appears. It is platform-independent, so Windows, macOS, and Linux are all affected.Fix
ws's optional native addons (bufferutil,utf-8-validate, required inside a try/catch) stay external.electron-squirrel-startupwas a second straggler: it was loaded through a rawrequire(), which stays external even when bundling, so it became the next crash. Imported it instead so it bundles, with a small local type declaration since it ships no types.ajv(via electron-store) is a non-issue: the app passes electron-store no schema, so ajv never compiles anything and its dynamic requires are dead code.Verification
Built an actual package and launched it: both windows render, the dashboard loads (42 controls), and there are no module errors. This is the packaged-build test that dev-mode runs (
npm start, which resolvesnode_modulesdirectly) could never catch, which is how this slipped through the earlier releases.Bumps to v0.20.1.
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Chores