Skip to content

fix: package Electron runtime deps - #1639

Merged
diegosouzapw merged 3 commits into
cheaper-inference:release/v3.7.1from
prateek:prateek/osx-electron-runtime-deps
Apr 27, 2026
Merged

diegosouzapw merged 3 commits into
cheaper-inference:release/v3.7.1from
prateek:prateek/osx-electron-runtime-deps

Conversation

@prateek

@prateek prateek commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix the packaged Electron app startup failure where server.js is present but runtime dependencies such as next are missing from resources/app/node_modules.

The previous v3.7.0 fix added node_modules/**/* to the parent extraResources filter, but release artifacts can still ship an empty resources/app/node_modules. This adds a separate extraResources FileSet that names the standalone node_modules directory directly.

Closes #1636.
Refs #1492.

Why

The Electron main process starts the packaged Next standalone server from resources/app/server.js. That server needs the standalone runtime dependencies under resources/app/node_modules.

Without them, the server exits with:

Cannot find module 'next'

The Electron window then loads a dead local URL and appears as a black screen.

Changes

  • Copy .next/electron-standalone/node_modules directly to resources/app/node_modules.
  • Keep native modules such as better-sqlite3 handled by app.asar.unpacked/node_modules.
  • Add a unit guard for the Electron builder config.
  • Add a packaged macOS app smoke check that launches the built .app, waits for /login to return HTTP 200, and fails on startup module-load errors.
  • Run the smoke check in macOS Electron release jobs.

Validation

  • node --import tsx/esm --test tests/unit/electron-packaging.test.ts
  • npm run build
  • CSC_IDENTITY_AUTO_DISCOVERY=false npm run pack --prefix electron
  • npm run electron:smoke:packaged

The smoke test confirms the packaged app starts, serves /login, and does not emit MODULE_NOT_FOUND / Cannot find module startup errors.

cheaper-inference#1630)

Cherry-pick from PR cheaper-inference#1630 by @rdself. Fixes Docker build failures caused by
lockfile peer dependency mismatch during npm ci.
…ailures

- Override plist to v4.0.0 which passes mandatory mimeType to DOMParser
- Add USERPROFILE sanitization on Windows to avoid EPERM on junction points
- Add NPM_CONFIG_LEGACY_PEER_DEPS to Electron workflow install step
@prateek
prateek requested a review from diegosouzapw as a code owner April 27, 2026 00:22

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a smoke test for the packaged Electron application and ensures that standalone runtime dependencies are correctly included in the build. Key changes include the addition of a macOS-specific smoke test script, a corresponding npm script, and a unit test to verify the packaging configuration. Feedback was provided to extend the smoke test script to support Windows and Linux platforms, ensuring consistent validation across all target environments.

Comment thread scripts/smoke-electron-packaged.mjs Outdated
Comment on lines +115 to +117
if (platform() !== "darwin") {
throw new Error("Packaged Electron smoke check currently supports macOS .app bundles only.");
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The smoke test is currently restricted to macOS. Since the application is also built for Windows and Linux (as seen in electron/package.json), consider extending this script to support these platforms. This would involve adjusting the executable discovery logic to look for .exe on Windows or the binary name on Linux, ensuring consistent validation across all target environments.

@prateek
prateek force-pushed the prateek/osx-electron-runtime-deps branch from 4b3026b to d1054a9 Compare April 27, 2026 00:31
@prateek

prateek commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review feedback in d1054a9.

The packaged smoke script now discovers and launches macOS, Windows, and Linux unpacked Electron builds. The release workflow runs it on every Electron build matrix entry; Linux uses xvfb-run so the packaged app can start under CI.

Fork-Patch: electron-standalone-runtime-deps

Reason: the packaged desktop app starts server.js from resources/app, so the standalone Next runtime dependencies must be present under resources/app/node_modules.
@prateek
prateek force-pushed the prateek/osx-electron-runtime-deps branch from d1054a9 to 29af01f Compare April 27, 2026 00:51
@prateek

prateek commented Apr 27, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the follow-up review items in 29af01f.

Changes made:

  • Linux packaged smoke now discovers the default electron-builder executable name (omniroute-desktop).
  • The smoke runner launches the packaged app with an allowlisted, temp-profile environment instead of inheriting the full CI environment.
  • App/server logs are buffered and only printed on failure by default; ELECTRON_SMOKE_STREAM_LOGS=1 keeps the old live log behavior.
  • Shutdown now targets the process tree, verifies the smoke URL closes before deleting the temp data dir, and holds a short post-ready settle window.
  • Fatal log detection now catches Electron unhandled rejections and uncaught exceptions.
  • PR CI now has an Ubuntu Electron Package Smoke job that builds electron --dir and runs the packaged smoke under xvfb-run.

Local validation passed: unit tests for packaging/smoke helpers, node --check, local Electron --dir pack, and packaged smoke on macOS.

@diegosouzapw
diegosouzapw changed the base branch from main to release/v3.7.1 April 27, 2026 02:51
@diegosouzapw
diegosouzapw merged commit 56ae1b8 into cheaper-inference:release/v3.7.1 Apr 27, 2026
1 of 2 checks passed
@diegosouzapw

Copy link
Copy Markdown
Collaborator

Thanks @prateek for this comprehensive fix! 🎉 The separate extraResources FileSet approach is the right solution for ensuring node_modules/ reaches the packaged app. The smoke test script is excellent — cross-platform process management, security-conscious env allowlisting, and fatal log pattern detection will catch this class of regression in CI going forward. Merged into release/v3.7.1 and will close #1636. We really appreciate this quality contribution!

HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
Integrated into release/v3.7.1 — fixes Electron installer shipping empty node_modules. Adds separate extraResources FileSet, CI smoke test job, and cross-platform packaged app validation script. Closes cheaper-inference#1636.
Poid-ZA pushed a commit to Poid-ZA/OmniRoute that referenced this pull request Aug 5, 2026
Integrated into release/v3.7.1 — fixes Electron installer shipping empty node_modules. Adds separate extraResources FileSet, CI smoke test job, and cross-platform packaged app validation script. Closes cheaper-inference#1636.
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
Integrated into release/v3.7.1 — fixes Electron installer shipping empty node_modules. Adds separate extraResources FileSet, CI smoke test job, and cross-platform packaged app validation script. Closes cheaper-inference#1636.
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.

Regression in v3.7.0: installer still ships empty node_modules, server crashes with "Cannot find module 'next'" (#1492 fix not effective)

2 participants