Skip to content

Fix Windows dev startup when ELECTRON_RUN_AS_NODE is set#8445

Open
noaft wants to merge 3 commits into
BasedHardware:mainfrom
noaft:fix/windows-dev-preflight
Open

Fix Windows dev startup when ELECTRON_RUN_AS_NODE is set#8445
noaft wants to merge 3 commits into
BasedHardware:mainfrom
noaft:fix/windows-dev-preflight

Conversation

@noaft

@noaft noaft commented Jun 27, 2026

Copy link
Copy Markdown

Summary

  • Add a Windows desktop dev wrapper that unsets ELECTRON_RUN_AS_NODE before launching electron-vite dev
  • Keep the existing npm run dev command unchanged for developers
  • Document why the wrapper exists in the Windows README

Why

If ELECTRON_RUN_AS_NODE=1 leaks into the shell, Electron starts as a Node runtime instead of an Electron app. That makes electron.app undefined and crashes startup inside @electron-toolkit/utils.

Testing

  • npm run typecheck
  • npx eslint scripts/dev.mjs
  • Verified ELECTRON_RUN_AS_NODE=1 npm run dev starts without the previous electron.app.isPackaged crash

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files

Confidence score: 4/5

  • In desktop/windows/package.json (via scripts/dev.mjs), the dev wrapper drops CLI flags, so npm run dev -- <flags> won’t pass options through to electron-vite dev, which can mislead local debugging or platform-specific testing; before merging, update the wrapper to append process.argv (or equivalent) when spawning the dev command.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/windows/package.json">

<violation number="1" location="desktop/windows/package.json:15">
P2: The `dev` script wrapper does not forward CLI arguments to `electron-vite dev`. Any flags passed via `npm run dev -- <flags>` will be silently ignored because `scripts/dev.mjs` hard-codes `['dev']` instead of appending `process.argv.slice(2)`.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

"typecheck": "npm run typecheck:node && npm run typecheck:web",
"start": "electron-vite preview",
"dev": "electron-vite dev",
"dev": "node scripts/dev.mjs",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The dev script wrapper does not forward CLI arguments to electron-vite dev. Any flags passed via npm run dev -- <flags> will be silently ignored because scripts/dev.mjs hard-codes ['dev'] instead of appending process.argv.slice(2).

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/windows/package.json, line 15:

<comment>The `dev` script wrapper does not forward CLI arguments to `electron-vite dev`. Any flags passed via `npm run dev -- <flags>` will be silently ignored because `scripts/dev.mjs` hard-codes `['dev']` instead of appending `process.argv.slice(2)`.</comment>

<file context>
@@ -12,7 +12,7 @@
     "typecheck": "npm run typecheck:node && npm run typecheck:web",
     "start": "electron-vite preview",
-    "dev": "electron-vite dev",
+    "dev": "node scripts/dev.mjs",
     "build": "npm run typecheck && electron-vite build",
     "rebuild:sqlite": "electron-rebuild -f -w better-sqlite3",
</file context>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

@Git-on-my-level Git-on-my-level added workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior needs-maintainer-review Needs a human maintainer to review/approve (e.g. stacked, product, or architecture judgment) labels Jun 27, 2026

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the focused Windows dev-startup fix — the underlying problem makes sense, and unsetting ELECTRON_RUN_AS_NODE only for the spawned Electron app is the right direction.

I think this needs one small robustness pass before merge:

  • The wrapper spawns the resolved node_modules/.bin/electron-vite path with shell: true. That makes the command depend on shell parsing, so checkouts whose path contains spaces can fail, and forwarded dev flags can be interpreted by the shell instead of being passed literally to electron-vite. Since npm run dev is a local developer entrypoint, it should preserve the old script's argument behavior as closely as possible.

Could you update the wrapper to avoid shell parsing on platforms where it is not needed, and keep arguments passed literally? For example, spawn the binary from node_modules/.bin with shell: process.platform === 'win32' only if needed for the .cmd shim, or launch via a Node/npm entrypoint with cwd: root, and add/mention a quick verification for:

  • a repo path containing spaces, and
  • npm run dev -- <some electron-vite flag> still reaching electron-vite dev.

After that, this looks like a good targeted fix. I’m not formally approving because this changes the Windows dev workflow/package script and should get maintainer review before merge.

@noaft

noaft commented Jun 27, 2026

Copy link
Copy Markdown
Author

Updated in 5b081a340.

The wrapper no longer spawns the .bin/electron-vite(.cmd) shim with shell: true. It now launches the electron-vite JS entrypoint directly through the current Node executable:

spawn(process.execPath, [electronVite, ...args], {
  cwd: root,
  env,
  shell: false,
  stdio: 'inherit'
})

This avoids shell parsing entirely while preserving forwarded args from npm run dev -- <flags>.

Verified:

  • npx eslint scripts/dev.mjs
  • ELECTRON_RUN_AS_NODE=1 node scripts/dev.mjs --help
  • Path-with-spaces junction + node "...\\scripts\\dev.mjs" --help
  • node scripts/dev.mjs --rendererOnly --clearScreen false

--rendererOnly reached electron-vite as expected:

skipped building main process and preload scripts

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 1 file (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="desktop/windows/scripts/dev.mjs">

<violation number="1" location="desktop/windows/scripts/dev.mjs:10">
P2: Hardcoding the `electron-vite` internal path (`node_modules/electron-vite/bin/electron-vite.js`) instead of using the package-manager `.bin` shim makes the launcher brittle to upstream package structure changes.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

const env = { ...process.env }
const args = ['dev', ...process.argv.slice(2)]
const root = join(dirname(fileURLToPath(import.meta.url)), '..')
const electronVite = join(root, 'node_modules', 'electron-vite', 'bin', 'electron-vite.js')

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Hardcoding the electron-vite internal path (node_modules/electron-vite/bin/electron-vite.js) instead of using the package-manager .bin shim makes the launcher brittle to upstream package structure changes.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At desktop/windows/scripts/dev.mjs, line 10:

<comment>Hardcoding the `electron-vite` internal path (`node_modules/electron-vite/bin/electron-vite.js`) instead of using the package-manager `.bin` shim makes the launcher brittle to upstream package structure changes.</comment>

<file context>
@@ -7,12 +7,7 @@ import { fileURLToPath } from 'node:url'
-  '.bin',
-  process.platform === 'win32' ? 'electron-vite.cmd' : 'electron-vite'
-)
+const electronVite = join(root, 'node_modules', 'electron-vite', 'bin', 'electron-vite.js')
 
 if (env.ELECTRON_RUN_AS_NODE) {
</file context>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

done

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for the update. The current wrapper looks like it addresses the robustness concerns I had: it forwards npm run dev -- ... arguments, avoids shell parsing by invoking the electron-vite JS bin through the current Node executable, runs from the Windows desktop package root, and only removes ELECTRON_RUN_AS_NODE from the spawned Electron dev process.

I also checked that electron-vite@5.0.0 exposes bin/electron-vite.js, and the wrapper parses cleanly with Node. This is a positive signal from my side.

I’m still not formally approving because this changes the Windows dev/package-script workflow and the PR is already marked for maintainer/workflow review. A human maintainer should make the final call before merge.

@noaft noaft requested a review from Git-on-my-level June 28, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-maintainer-review Needs a human maintainer to review/approve (e.g. stacked, product, or architecture judgment) workflow-review Needs maintainer review for workflow, automation, hooks, or CI behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants