Strip ELECTRON_RUN_AS_NODE from desktop dev launch #187

Closed
opened 2026-06-01 06:59:36 +00:00 by steve · 0 comments
Owner

pnpm dev:desktop can inherit ELECTRON_RUN_AS_NODE from the invoking
package-manager environment. When that happens, the dev orchestrator launches
the Electron binary as plain Node, so the desktop main process crashes before
the renderer can show the current dev UI.

Problem

Running:

LAPIS_DESKTOP_TEST_VAULT_PATH=/Users/stevejuma/code/lapis-notes/e2e-vault-temp \
LAPIS_DESKTOP_DISABLE_DEVTOOLS=1 \
pnpm dev:desktop

starts Vite and compiles the Electron main/preload build, but the spawned
Electron process crashes with:

TypeError: Cannot read properties of undefined (reading 'registerSchemesAsPrivileged')

The same renderer and built main process work when Playwright launches Electron
through the existing helpers because those helpers strip ELECTRON_RUN_AS_NODE
before launch.

Goal

Make pnpm dev:desktop launch the real Electron runtime consistently, including
when the parent shell, pnpm, Turbo, or test tooling has ELECTRON_RUN_AS_NODE
set.

Scope

  • Sanitize the environment passed from
    packages/desktop-electron/scripts/dev.mjs to the spawned Electron process.
  • Preserve existing dev-server URL, test-vault path, and desktop devtools env
    behavior.
  • Add focused coverage or validation that the desktop dev launch path strips the
    Node-mode Electron flag.
  • Verify the root pnpm dev:desktop command by exercising the spawned Electron
    app rather than only checking process logs.
  • Make a user-initiated Electron app exit shut down the dev orchestrator so the
    terminal session does not keep Vite and TypeScript watchers alive.
  • Pass desktop dev environment variables through Turbo so
    LAPIS_DESKTOP_TEST_VAULT_PATH, debug-port probes, and related desktop env
    controls reach the package dev launcher from the repo-root command.

Non-goals

  • Changing the registry settings UI.
  • Changing packaged desktop launch behavior.
  • Reworking the desktop dev orchestrator beyond the inherited environment bug.
  • Changing the hot-reload behavior for TypeScript rebuilds while Electron is
    still running.

Acceptance Criteria

  • pnpm dev:desktop no longer launches Electron with ELECTRON_RUN_AS_NODE.
  • With LAPIS_DESKTOP_TEST_VAULT_PATH=e2e-vault-temp, the command reaches the
    desktop renderer instead of crashing in dist-electron/main.js.
  • With the root command running against e2e-vault-temp, the app can open
    Settings and render the Plugin registry tab.
  • Closing the spawned Electron app causes the pnpm dev:desktop shell command
    to terminate cleanly instead of leaving the watcher process alive.
  • Repo-root pnpm dev:desktop forwards the LAPIS_DESKTOP_* environment
    variables needed by desktop test-vault and verification flows.
  • Existing Playwright Electron helpers and smoke behavior remain compatible.
  • Required desktop package checks pass.

Implementation Notes

  • The existing E2E helper createElectronLaunchEnv() already deletes
    ELECTRON_RUN_AS_NODE; mirror that defensive behavior in the dev
    orchestrator.
  • The reproduced crash happens before registry settings can render, which made
    the issue look like a missing settings tab even though the settings
    registration path passes when Electron launches correctly.
  • The first fix verified the child process reached Electron runtime, but it did
    not automate the rendered UI state from the root pnpm dev:desktop command.
    Add or use a command-level probe that starts the root script and inspects the
    spawned Electron app.
  • Reproduction with the packaged app already running showed the dev Electron
    process could exit immediately on the single-instance lock, leaving the
    terminal watcher alive and focusing the installed app instead.
  • A command-level debug probe also showed Turbo was not forwarding the temporary
    remote-debugging env var, so desktop dev env pass-through has to be explicit
    at the root task level.

Suggested Files or Specs To Inspect

  • packages/desktop-electron/scripts/dev.mjs
  • packages/desktop-electron/e2e/helpers.ts
  • packages/desktop-electron/src-electron/main.ts
  • packages/desktop-electron/e2e/plugin-registry.spec.ts
  • turbo.json
  • spec/src/20-packages/desktop-electron/index.md

Validation Commands

  • LAPIS_DESKTOP_TEST_VAULT_PATH=/Users/stevejuma/code/lapis-notes/e2e-vault-temp LAPIS_DESKTOP_DISABLE_DEVTOOLS=1 pnpm dev:desktop
  • A root-command probe that starts pnpm dev:desktop, opens Settings in the
    spawned Electron window, verifies the Plugin registry panel, closes Electron,
    and verifies the shell process exits.
  • pnpm --filter @lapis-notes/desktop-electron check:all
  • pnpm --filter @lapis-notes/desktop-electron check:e2e

Follow-up Tasks

Implementation Summary

Updated pnpm dev:desktop so Turbo forwards desktop test/debug env, the dev launcher strips Node-mode state while using an isolated repo-scoped userData directory, the macOS dev window close quits Electron/watchers, and verified the root command renders Plugin registry against e2e-vault-temp and exits cleanly.

Reopen Reason

Regression follow-up: pnpm dev:desktop still does not reliably render the expected Electron settings UI, and closing the Electron app leaves the dev shell running.

`pnpm dev:desktop` can inherit `ELECTRON_RUN_AS_NODE` from the invoking package-manager environment. When that happens, the dev orchestrator launches the Electron binary as plain Node, so the desktop main process crashes before the renderer can show the current dev UI. ## Problem Running: ```bash LAPIS_DESKTOP_TEST_VAULT_PATH=/Users/stevejuma/code/lapis-notes/e2e-vault-temp \ LAPIS_DESKTOP_DISABLE_DEVTOOLS=1 \ pnpm dev:desktop ``` starts Vite and compiles the Electron main/preload build, but the spawned Electron process crashes with: ```text TypeError: Cannot read properties of undefined (reading 'registerSchemesAsPrivileged') ``` The same renderer and built main process work when Playwright launches Electron through the existing helpers because those helpers strip `ELECTRON_RUN_AS_NODE` before launch. ## Goal Make `pnpm dev:desktop` launch the real Electron runtime consistently, including when the parent shell, pnpm, Turbo, or test tooling has `ELECTRON_RUN_AS_NODE` set. ## Scope - Sanitize the environment passed from `packages/desktop-electron/scripts/dev.mjs` to the spawned Electron process. - Preserve existing dev-server URL, test-vault path, and desktop devtools env behavior. - Add focused coverage or validation that the desktop dev launch path strips the Node-mode Electron flag. - Verify the root `pnpm dev:desktop` command by exercising the spawned Electron app rather than only checking process logs. - Make a user-initiated Electron app exit shut down the dev orchestrator so the terminal session does not keep Vite and TypeScript watchers alive. - Pass desktop dev environment variables through Turbo so `LAPIS_DESKTOP_TEST_VAULT_PATH`, debug-port probes, and related desktop env controls reach the package dev launcher from the repo-root command. ## Non-goals - Changing the registry settings UI. - Changing packaged desktop launch behavior. - Reworking the desktop dev orchestrator beyond the inherited environment bug. - Changing the hot-reload behavior for TypeScript rebuilds while Electron is still running. ## Acceptance Criteria - `pnpm dev:desktop` no longer launches Electron with `ELECTRON_RUN_AS_NODE`. - With `LAPIS_DESKTOP_TEST_VAULT_PATH=e2e-vault-temp`, the command reaches the desktop renderer instead of crashing in `dist-electron/main.js`. - With the root command running against `e2e-vault-temp`, the app can open Settings and render the Plugin registry tab. - Closing the spawned Electron app causes the `pnpm dev:desktop` shell command to terminate cleanly instead of leaving the watcher process alive. - Repo-root `pnpm dev:desktop` forwards the `LAPIS_DESKTOP_*` environment variables needed by desktop test-vault and verification flows. - Existing Playwright Electron helpers and smoke behavior remain compatible. - Required desktop package checks pass. ## Implementation Notes - The existing E2E helper `createElectronLaunchEnv()` already deletes `ELECTRON_RUN_AS_NODE`; mirror that defensive behavior in the dev orchestrator. - The reproduced crash happens before registry settings can render, which made the issue look like a missing settings tab even though the settings registration path passes when Electron launches correctly. - The first fix verified the child process reached Electron runtime, but it did not automate the rendered UI state from the root `pnpm dev:desktop` command. Add or use a command-level probe that starts the root script and inspects the spawned Electron app. - Reproduction with the packaged app already running showed the dev Electron process could exit immediately on the single-instance lock, leaving the terminal watcher alive and focusing the installed app instead. - A command-level debug probe also showed Turbo was not forwarding the temporary remote-debugging env var, so desktop dev env pass-through has to be explicit at the root task level. ## Suggested Files or Specs To Inspect - `packages/desktop-electron/scripts/dev.mjs` - `packages/desktop-electron/e2e/helpers.ts` - `packages/desktop-electron/src-electron/main.ts` - `packages/desktop-electron/e2e/plugin-registry.spec.ts` - `turbo.json` - `spec/src/20-packages/desktop-electron/index.md` ## Validation Commands - `LAPIS_DESKTOP_TEST_VAULT_PATH=/Users/stevejuma/code/lapis-notes/e2e-vault-temp LAPIS_DESKTOP_DISABLE_DEVTOOLS=1 pnpm dev:desktop` - A root-command probe that starts `pnpm dev:desktop`, opens Settings in the spawned Electron window, verifies the Plugin registry panel, closes Electron, and verifies the shell process exits. - `pnpm --filter @lapis-notes/desktop-electron check:all` - `pnpm --filter @lapis-notes/desktop-electron check:e2e` ## Related Issues - Follow-up to #184 — [Cover and fix Electron registry settings visibility](../closed/184-cover-and-fix-electron-registry-settings-visibility.md) ## Follow-up Tasks ## Implementation Summary Updated pnpm dev:desktop so Turbo forwards desktop test/debug env, the dev launcher strips Node-mode state while using an isolated repo-scoped userData directory, the macOS dev window close quits Electron/watchers, and verified the root command renders Plugin registry against e2e-vault-temp and exits cleanly. ## Reopen Reason Regression follow-up: pnpm dev:desktop still does not reliably render the expected Electron settings UI, and closing the Electron app leaves the dev shell running. <!-- backlog:task_id=TASK-DESKTOP-DEV-ELECTRON-RUN-AS-NODE source_spec=spec/src/20-packages/desktop-electron/index.md related_issue=184 -->
steve added this to the Full Registry V1 milestone 2026-06-01 06:59:36 +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
lapis-notes/lapis#187
No description provided.