Skip to content

fix: repair broken Electron install on macOS via system unzip - #11

Open
dan-nyanko wants to merge 2 commits into
Flowdesktech:masterfrom
dan-nyanko:fix/electron-install-macos
Open

fix: repair broken Electron install on macOS via system unzip#11
dan-nyanko wants to merge 2 commits into
Flowdesktech:masterfrom
dan-nyanko:fix/electron-install-macos

Conversation

@dan-nyanko

Copy link
Copy Markdown

Summary

On macOS, pnpm install could leave Electron in a broken state where require('electron') fails with "Electron failed to install correctly". This adds a postinstall step (scripts/ensure-electron.js) that detects the broken state and re-extracts the cached Electron archive using the system unzip tool.

Root cause

Electron's own install.js extracts via extract-zip, which on some systems silently extracts only a stub (no Frameworks), leaving a broken install. Upstream issue: electron/electron#51619 — extraction fails under newer Node.js versions because of a bug in extract-zip (yauzl/fd-slicer); the cached zip is present but dist is incomplete.

Fix

  • New scripts/ensure-electron.js postinstall:
    • isUsable() checks that require('electron') resolves and (on macOS) that dist/Electron.app/Contents/Frameworks exists.
    • If broken, locates the cached electron-v<version>-<platform>-<arch>.zip (also checks the opposite arch under Rosetta, and any-version fallback), removes the stub dist, and re-extracts it with the system unzip.
    • On platforms without unzip (e.g. Windows), falls back to Electron's own installer.
    • Wrapped in try/catch and never fails the install — it only logs a warning and exits 0 so pnpm install always succeeds.
  • package.json: added "ensure-electron": "node scripts/ensure-electron.js" and "postinstall": "node scripts/ensure-electron.js".

Testing

  • rm -rf node_modules && pnpm install → postinstall detects/repairs via unzip; require('electron') resolves.
  • Verified graceful handling of missing/partial electron/package.json (repair only warns, install still succeeds).
  • pnpm run lint, pnpm run format:check, pnpm run typecheck → all pass (the script is plain JS, not covered by src lint/typecheck but formatted by prettier).

Note

This is a workaround until electron/electron#51619 is fixed upstream. The script is a no-op when the install is already usable.

jsdom does not reliably expose localStorage across runtimes (e.g. Node 26's
experimental built-in shadows it), causing projectsPersistence/projectsSlice
tests to fail with 'localStorage is undefined'. Add a minimal in-memory shim
guarded by typeof check so it only applies when absent, keeping behavior
identical on environments where jsdom already provides it.
Electron's install.js uses extract-zip, which on some macOS machines silently extracts only a stub (no Frameworks), causing "Electron failed to install correctly". Add an idempotent postinstall (scripts/ensure-electron.js) that detects a broken install and re-extracts the cached archive with the system unzip tool.
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