app: production renderer never boots — node builtins survive as ESM imports the file:// loader cannot resolve #233

Closed
opened 2026-07-31 19:23:12 +00:00 by ben · 2 comments
Owner

Parent

Found during #183 Phase A (A1, first real launch of the production shell). Reported during the same QA thread as #230–#232.

What happened

The operator app's production shell opened to a blank window on its very first real launch. The renderer's built bundles keep the node builtins (node:child_process, node:fs/promises, node:path) as ESM imports; loaded from file://, Chromium's module loader cannot resolve the node: scheme (ERR_UNKNOWN_URL_SCHEME) and the production entry never executes. Node integration provides CJS require to the renderer, not the ESM loader — the build's stated assumption ("resolved at runtime by the node-integrated renderer") does not hold for module-script imports.

The production renderer has never been bootable — the boot seam test runs under vitest in Node, where node: ESM imports resolve fine, so it structurally cannot catch this. This is drift on the real-composition ticket's promise (#191): the packaged app's assets were built but never loaded in the shell.

What I expected

The production shell boots the real composition (data-build="production" on the root) from the built assets, packaged or unpackaged.

Steps to reproduce

  1. Build the shell's assets and launch Electron against the built main bundle (no dev server).
  2. The window opens blank; the console shows ERR_UNKNOWN_URL_SCHEME for the node builtin imports and a failed dynamic import of the production entry.

Additional context

  • A local fix is already applied on the operator laptop (uncommitted, in the renderer build config): a build-only bridge that compiles each node-builtin import to a module resolving it through the renderer's require, with syntheticNamedExports. External list shrinks to electron alone. Renderer rebuilt cleanly; all 44 app test files (386 tests) and the typecheck pass. This ticket is for landing that fix (or an equivalent, e.g. the established electron-renderer plugin approach) properly.
  • A durable guard is the real ask: the seam tests run in Node and cannot see Chromium-loader failures. Either a post-build assertion that no node:/bare-builtin ESM imports survive in the built renderer chunks, or a minimal real-shell boot smoke, so the packaged path cannot silently regress again.
## Parent Found during #183 Phase A (A1, first real launch of the production shell). Reported during the same QA thread as #230–#232. ## What happened The operator app's production shell opened to a blank window on its very first real launch. The renderer's built bundles keep the node builtins (`node:child_process`, `node:fs/promises`, `node:path`) as ESM imports; loaded from `file://`, Chromium's module loader cannot resolve the `node:` scheme (`ERR_UNKNOWN_URL_SCHEME`) and the production entry never executes. Node integration provides CJS `require` to the renderer, not the ESM loader — the build's stated assumption ("resolved at runtime by the node-integrated renderer") does not hold for module-script imports. **The production renderer has never been bootable** — the boot seam test runs under vitest in Node, where `node:` ESM imports resolve fine, so it structurally cannot catch this. This is drift on the real-composition ticket's promise (#191): the packaged app's assets were built but never loaded in the shell. ## What I expected The production shell boots the real composition (`data-build="production"` on the root) from the built assets, packaged or unpackaged. ## Steps to reproduce 1. Build the shell's assets and launch Electron against the built main bundle (no dev server). 2. The window opens blank; the console shows `ERR_UNKNOWN_URL_SCHEME` for the node builtin imports and a failed dynamic import of the production entry. ## Additional context - **A local fix is already applied on the operator laptop** (uncommitted, in the renderer build config): a build-only bridge that compiles each node-builtin import to a module resolving it through the renderer's `require`, with `syntheticNamedExports`. External list shrinks to `electron` alone. Renderer rebuilt cleanly; all 44 app test files (386 tests) and the typecheck pass. This ticket is for landing that fix (or an equivalent, e.g. the established electron-renderer plugin approach) properly. - **A durable guard is the real ask**: the seam tests run in Node and cannot see Chromium-loader failures. Either a post-build assertion that no `node:`/bare-builtin ESM imports survive in the built renderer chunks, or a minimal real-shell boot smoke, so the packaged path cannot silently regress again.
Author
Owner

This was generated by AI during triage.

Triage

Category: bug · State: ready-for-agent

Verification: confirmed by inspection — app/vite.config.ts sets external: ['electron', ...builtinModules, ...builtinModules.map(m => 'node:'+m)] on the renderer build, and app/src/lib/stdioBridge.ts / app/src/entry/channel.ts (both reachable from the renderer entry) import node:child_process, node:fs/promises, node:path. Those survive the renderer build as real node: ESM imports, which resolve fine under Vite's dev server and under vitest (Node) but not under Chromium's file:// module loader — matching the reported ERR_UNKNOWN_URL_SCHEME. Root cause confirmed in code; not yet fixed anywhere in the repo.

Agent Brief

Category: bug
Summary: The packaged operator app's production renderer never boots — built chunks keep node: builtins as ESM imports, which Chromium's file:// loader cannot resolve.

Current behavior:
The renderer's Vite build config keeps node builtins external (alongside electron) so node-builtin imports reachable from the renderer entry (e.g. stdioBridge's node:child_process, channel.ts's node:fs/promises/node:path) survive in the built chunks as real ESM imports. That resolves fine under Vite's dev server and under vitest (Node), but when the built bundle is loaded from file:// in the packaged Electron shell, Chromium's module loader cannot resolve the node: scheme (ERR_UNKNOWN_URL_SCHEME), and the production entry never executes — the window opens blank. The existing boot seam test runs under vitest in Node, where node: ESM imports resolve fine, so it structurally cannot catch this.

Desired behavior:
The packaged production renderer boots successfully from file://, with the node-builtin-backed code reachable through Electron's node-integrated require bridge rather than surviving as unresolved ESM imports in the browser-loaded module graph. A durable guard exists so this class of failure can't silently regress: either a post-build assertion that no bare/node: builtin ESM imports survive in the built renderer chunks, or a minimal real-shell boot smoke test that runs outside vitest/Node.

Key interfaces:

  • The renderer's Vite build config — the external list for node builtins is the root cause. An approach like compiling each node-builtin import through a build-only bridge resolved via the renderer's require (with syntheticNamedExports), or an established electron-renderer Vite plugin that does the same, resolves it while keeping electron itself external.
  • Any post-build check or smoke test added should run in a context that can observe Chromium-loader failures (not just vitest/Node), so it complements rather than duplicates the existing boot seam test.

Acceptance criteria:

  • Building the renderer's production assets and loading them in a packaged/production Electron shell (no dev server) boots the real composition without ERR_UNKNOWN_URL_SCHEME or a blank window.
  • All existing app tests and the typecheck continue to pass.
  • A durable guard (build-time assertion or a real-shell boot smoke test) exists that would catch a regression of this class, distinct from the existing Node-based boot seam test.

Out of scope:

  • Packaging/installer work (#230/#231).
  • Migrating to the full Quasar app-vite UI layer (ADR 0108, separate deferred work).

Note: the reporter mentions a local, uncommitted fix already applied on their machine (a build-only node-builtin bridge). That fix is not present in the repo — treat it as unavailable and implement a fix independently (the approach it describes, or an equivalent plugin-based one, is a reasonable starting point, not a constraint).

> *This was generated by AI during triage.* ## Triage **Category:** bug · **State:** ready-for-agent **Verification:** confirmed by inspection — `app/vite.config.ts` sets `external: ['electron', ...builtinModules, ...builtinModules.map(m => 'node:'+m)]` on the renderer build, and `app/src/lib/stdioBridge.ts` / `app/src/entry/channel.ts` (both reachable from the renderer entry) import `node:child_process`, `node:fs/promises`, `node:path`. Those survive the renderer build as real `node:` ESM imports, which resolve fine under Vite's dev server and under vitest (Node) but not under Chromium's `file://` module loader — matching the reported `ERR_UNKNOWN_URL_SCHEME`. Root cause confirmed in code; not yet fixed anywhere in the repo. ## Agent Brief **Category:** bug **Summary:** The packaged operator app's production renderer never boots — built chunks keep `node:` builtins as ESM imports, which Chromium's `file://` loader cannot resolve. **Current behavior:** The renderer's Vite build config keeps node builtins external (alongside `electron`) so node-builtin imports reachable from the renderer entry (e.g. `stdioBridge`'s `node:child_process`, `channel.ts`'s `node:fs/promises`/`node:path`) survive in the built chunks as real ESM imports. That resolves fine under Vite's dev server and under vitest (Node), but when the built bundle is loaded from `file://` in the packaged Electron shell, Chromium's module loader cannot resolve the `node:` scheme (`ERR_UNKNOWN_URL_SCHEME`), and the production entry never executes — the window opens blank. The existing boot seam test runs under vitest in Node, where `node:` ESM imports resolve fine, so it structurally cannot catch this. **Desired behavior:** The packaged production renderer boots successfully from `file://`, with the node-builtin-backed code reachable through Electron's node-integrated `require` bridge rather than surviving as unresolved ESM imports in the browser-loaded module graph. A durable guard exists so this class of failure can't silently regress: either a post-build assertion that no bare/`node:` builtin ESM imports survive in the built renderer chunks, or a minimal real-shell boot smoke test that runs outside vitest/Node. **Key interfaces:** - The renderer's Vite build config — the `external` list for node builtins is the root cause. An approach like compiling each node-builtin import through a build-only bridge resolved via the renderer's `require` (with `syntheticNamedExports`), or an established electron-renderer Vite plugin that does the same, resolves it while keeping `electron` itself external. - Any post-build check or smoke test added should run in a context that can observe Chromium-loader failures (not just vitest/Node), so it complements rather than duplicates the existing boot seam test. **Acceptance criteria:** - [ ] Building the renderer's production assets and loading them in a packaged/production Electron shell (no dev server) boots the real composition without `ERR_UNKNOWN_URL_SCHEME` or a blank window. - [ ] All existing app tests and the typecheck continue to pass. - [ ] A durable guard (build-time assertion or a real-shell boot smoke test) exists that would catch a regression of this class, distinct from the existing Node-based boot seam test. **Out of scope:** - Packaging/installer work (#230/#231). - Migrating to the full Quasar app-vite UI layer (ADR 0108, separate deferred work). **Note:** the reporter mentions a local, uncommitted fix already applied on their machine (a build-only node-builtin bridge). That fix is not present in the repo — treat it as unavailable and implement a fix independently (the approach it describes, or an equivalent plugin-based one, is a reasonable starting point, not a constraint).
Author
Owner

Fixed in b09e951 (on origin/main).

Root cause: the renderer's Vite build kept node builtins in the external list, so node:child_process (stdioBridge), node:fs/promises + node:path (channel.ts) survived the renderer build as real node: ESM imports. Chromium's file:// module loader cannot resolve the node: scheme (ERR_UNKNOWN_URL_SCHEME) — the production entry never ran and the window opened blank. Node integration hands the renderer CJS require, not the ESM loader.

Fix: a build-only Vite plugin (app/vite-plugin-electron-builtins.ts) compiles each node-builtin import to a module resolving it through the renderer's runtime require, with Rollup syntheticNamedExports so { spawn }/{ join } named imports keep working. The renderer external list shrinks to electron alone (which the renderer never imports). The Electron main/preload (CJS) build is unchanged. Verified: the built dist chunks now carry require("node:child_process") / node:fs/promises / node:path and zero surviving node: ESM imports.

Durable guard: app/tests/unit/rendererBuild.test.ts runs the real renderer build in-memory (write: false) and asserts no node builtin survives as an external import (and that the builtins are bridged via require). It fails when the fix is reverted, and is distinct from the go-gated Node boot seam test — which resolves node: fine under Node and so structurally cannot see the Chromium-loader failure. A real-shell boot smoke was the other option, but the swarm/CI never downloads the Electron binary (pnpm-workspace.yaml denies its postinstall), so the build-output assertion is the CI-viable guard.

Checks: 402 app tests pass (the go-gated boot.test.ts needs go on PATH via nix develop — unrelated to this change); vue-tsc typecheck clean; eslint + prettier clean. Out of scope: packaging/installer (#230/#231), the Quasar app-vite layer (ADR 0108).

Fixed in b09e951 (on `origin/main`). **Root cause:** the renderer's Vite build kept node builtins in the `external` list, so `node:child_process` (`stdioBridge`), `node:fs/promises` + `node:path` (`channel.ts`) survived the renderer build as real `node:` ESM imports. Chromium's `file://` module loader cannot resolve the `node:` scheme (`ERR_UNKNOWN_URL_SCHEME`) — the production entry never ran and the window opened blank. Node integration hands the renderer CJS `require`, not the ESM loader. **Fix:** a build-only Vite plugin (`app/vite-plugin-electron-builtins.ts`) compiles each node-builtin import to a module resolving it through the renderer's runtime `require`, with Rollup `syntheticNamedExports` so `{ spawn }`/`{ join }` named imports keep working. The renderer `external` list shrinks to `electron` alone (which the renderer never imports). The Electron main/preload (CJS) build is unchanged. Verified: the built `dist` chunks now carry `require("node:child_process")` / `node:fs/promises` / `node:path` and **zero** surviving `node:` ESM imports. **Durable guard:** `app/tests/unit/rendererBuild.test.ts` runs the real renderer build in-memory (`write: false`) and asserts no node builtin survives as an external import (and that the builtins are bridged via `require`). It fails when the fix is reverted, and is distinct from the go-gated Node boot seam test — which resolves `node:` fine under Node and so structurally cannot see the Chromium-loader failure. A real-shell boot smoke was the other option, but the swarm/CI never downloads the Electron binary (`pnpm-workspace.yaml` denies its postinstall), so the build-output assertion is the CI-viable guard. **Checks:** 402 app tests pass (the go-gated `boot.test.ts` needs `go` on PATH via `nix develop` — unrelated to this change); `vue-tsc` typecheck clean; eslint + prettier clean. Out of scope: packaging/installer (#230/#231), the Quasar app-vite layer (ADR 0108).
ben closed this issue 2026-07-31 21:56:43 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#233
No description provided.