Skip to content

Fix packaged app crashing on launch (Cannot find module) - #32

Merged
JosephMaynard merged 2 commits into
masterfrom
fix/packaged-missing-modules
Aug 7, 2026
Merged

Fix packaged app crashing on launch (Cannot find module)#32
JosephMaynard merged 2 commits into
masterfrom
fix/packaged-missing-modules

Conversation

@JosephMaynard

@JosephMaynard JosephMaynard commented Aug 7, 2026

Copy link
Copy Markdown
Owner

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:

A JavaScript error occurred in the main process. Error: Cannot find module 'zod'

Root cause

The electron-forge Vite template marks every production dependency as external, so the compiled main.js does require('zod') (and every other dep) at runtime. But the packaged app.asar ships no node_modules at all, only the .vite build output and package.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

  • Bundle the dependencies into the main and preload output instead of externalising them. These processes use no native modules, so bundling is safe and makes the packaged app self-contained. Only Electron, Node builtins, and ws's optional native addons (bufferutil, utf-8-validate, required inside a try/catch) stay external.
  • electron-squirrel-startup was a second straggler: it was loaded through a raw require(), 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.
  • Confirmed 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 resolves node_modules directly) 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

    • Improved Windows installer startup handling, helping the application exit cleanly during installation and update events.
    • Improved application packaging compatibility for native modules.
  • Chores

    • Updated the application version to 0.20.1.

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>
@vercel

vercel Bot commented Aug 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
playoverlay Ready Ready Preview Aug 7, 2026 3:22pm

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b1dbe30b-9d4e-49e2-9586-f2cdd3608cba

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

The package version changes to 0.20.1. The main process uses a static, typed electron-squirrel-startup import. Vite externalizes Electron, Node builtins, and selected native modules while bundling other dependencies.

Changes

Application Packaging

Layer / File(s) Summary
Squirrel startup integration
src/main.ts, src/types/electron-squirrel-startup.d.ts
The main process uses the declared boolean startup flag and exits for Squirrel events.
Vite dependency externalization
vite.base.config.ts
Vite externalizes Electron, Node builtins, bufferutil, and utf-8-validate. Other dependencies are bundled.
Package release version
package.json
The package version changes from 0.20.0 to 0.20.1.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: fixing packaged app launch crashes caused by missing modules.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/packaged-missing-modules

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7d3a947 and b85caef.

📒 Files selected for processing (4)
  • package.json
  • src/main.ts
  • src/types/electron-squirrel-startup.d.ts
  • vite.base.config.ts

Comment thread package.json
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>
@JosephMaynard
JosephMaynard merged commit ce2bc60 into master Aug 7, 2026
7 checks passed
@JosephMaynard
JosephMaynard deleted the fix/packaged-missing-modules branch August 7, 2026 15:24
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.

1 participant