Skip to content

fix: ensure npm run dev works after npm install on Node v24+#4212

Merged
Jocs merged 4 commits into
developfrom
fix/npm-dev-node24-plus
May 15, 2026
Merged

fix: ensure npm run dev works after npm install on Node v24+#4212
Jocs merged 4 commits into
developfrom
fix/npm-dev-node24-plus

Conversation

@Jocs
Copy link
Copy Markdown
Member

@Jocs Jocs commented May 15, 2026

Summary

  • Move native-keymap from dependencies to optionalDependencies so npm ignores its auto-gyp compile failure on Node v24+ (C++20 not declared) and continues the install
  • Add scripts/postinstall.js replacing the fragile inline postinstall command — it restores native-keymap source (npm removes the dir on optional failure), downloads Electron, applies the C++20 patch, rebuilds native modules for Electron's ABI, and minifies locales
  • Write node_modules/electron/path.txt as a fallback when electron/install.js skips it on a cache hit — fixes the "Error: Electron uninstall" crash on npm run dev
  • Add include: ['native-keymap'] to externalizeDeps in electron.vite.config.js so Rollup externalizes the native addon instead of trying to bundle it (optional deps aren't auto-externalized)

Test plan

  • Fresh clone → npm install completes without error on Node v24/v26
  • npm run dev launches the Electron app
  • npm run build produces a distributable without errors
  • Re-running npm install (no changes) is idempotent — no spurious tree mutations

🤖 Generated with Claude Code

Move native-keymap to optionalDependencies so npm ignores its auto-gyp
failure on Node v24+, then restore and rebuild it correctly via a
dedicated postinstall script (scripts/postinstall.js).  The script also
writes path.txt for the Electron binary when install.js skips it due to
a cache hit, which was causing "Error: Electron uninstall" on npm run
dev.  Mark native-keymap as externalized in electron-vite so Rollup
does not try to bundle an optional native addon.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 15, 2026 09:29
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates install-time handling for native-keymap so development setup can recover from Node v24+ native build failures and still prepare Electron/native modules for npm run dev.

Changes:

  • Moves native-keymap to optionalDependencies.
  • Adds a cross-platform scripts/postinstall.js to restore, patch, rebuild, download Electron, and minify locales.
  • Externalizes native-keymap in the Electron main-process Vite build.

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 4 comments.

File Description
scripts/postinstall.js Adds scripted postinstall flow for native-keymap restoration, Electron setup, rebuild, and locale minification.
package.json Replaces inline postinstall command and moves native-keymap to optional dependencies.
package-lock.json Reflects native-keymap as an optional dependency.
electron.vite.config.js Ensures native-keymap is externalized during main-process bundling.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/postinstall.js Outdated
Comment thread scripts/postinstall.js
Comment thread scripts/postinstall.js Outdated
Comment thread scripts/postinstall.js Outdated
Jocs and others added 3 commits May 15, 2026 18:39
yauzl v2.10.0 openReadStream callback never fires for compressed entries
on Node v26+, causing extract-zip to silently exit with an incomplete
dist/ (Frameworks/ entirely missing). Detect this by checking whether
Electron.app/Contents/Frameworks exists after install.js runs; if it
doesn't, find the cached zip in ~/Library/Caches/electron and re-extract
with system unzip, which handles all entries correctly.

Also expand isComplete() to require Frameworks/ on macOS, so a partial
dist from a previous run is cleared and re-extracted on the next
npm install.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Reformat nested ternary to multiline (@stylistic/multiline-ternary,
@stylistic/operator-linebreak, @stylistic/indent) and replace template
literal strings with single-quoted strings (@stylistic/quotes).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Jocs Jocs merged commit 0d5678b into develop May 15, 2026
@Jocs Jocs deleted the fix/npm-dev-node24-plus branch May 15, 2026 11:12
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.

2 participants