Skip to content

Fix npm start on Windows: spawn via shell so npx resolves to npx.cmd#3627

Merged
fredrikekelund merged 2 commits into
trunkfrom
stu-1761-fix-windows-npm-start-enoent
May 29, 2026
Merged

Fix npm start on Windows: spawn via shell so npx resolves to npx.cmd#3627
fredrikekelund merged 2 commits into
trunkfrom
stu-1761-fix-windows-npm-start-enoent

Conversation

@ivan-ottinger
Copy link
Copy Markdown
Contributor

@ivan-ottinger ivan-ottinger commented May 27, 2026

Related issues

How AI was used in this PR

Diagnosed and patched with Claude Code. I reviewed the one-line change and verified it locally on Windows.

Proposed Changes

scripts/start-studio.mjs spawns npx vite ... and npx electron-vite ... with raw child_process.spawn(...). On Windows, npx is npx.cmd (a batch file), and Node's spawn without shell: true only resolves real executables — so npm start immediately throws Error: spawn npx ENOENT and the dev server never starts. macOS/Linux are unaffected because npx is a real binary there.

Fix: pass shell: true to the default spawn options inside spawnCommand. The shell resolves npxnpx.cmd on Windows and finds npx the usual way on macOS/Linux.

This was a latent bug in the predecessor scripts/start-new-ui.mjs (only reachable via the opt-in npm run start:new). #3537 promoted that script to default npm start, turning it into a Windows-wide blocker.

Why this is safe on macOS/Linux

  • All spawn args are hardcoded literals ('vite', '--port', '5200', etc.), so there's no shell-quoting risk.
  • stdio: 'inherit' still works through the shell wrapper.
  • SIGINT/SIGTERM handlers in the script already call .kill() on the child references, so Ctrl+C still works.

Caveat (not a regression vs. current state, but worth knowing): with shell: true the immediate child is the shell wrapper. If the parent script is killed abruptly, the inner vite/electron-vite may briefly outlive the wrapper until they notice their parent is gone. The script's own SIGINT/SIGTERM handlers cover the normal Ctrl+C path.

Testing Instructions

Windows (the regression):

  1. git checkout stu-1761-fix-windows-npm-start-enoent
  2. npm install && npm start
  3. Expected: prestart build runs, then Starting @studio/ui dev server on port 5200... followed by VITE vX ready in ... ms, then Electron launches.
  4. On trunk the same command throws Error: spawn npx ENOENT and exits with code 1.

macOS / Linux (regression check):

  1. npm start from this branch should behave identically to trunk — vite on 5200, then Electron.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@ivan-ottinger ivan-ottinger marked this pull request as ready for review May 27, 2026 12:27
@ivan-ottinger ivan-ottinger requested a review from Copilot May 27, 2026 12:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes npm start on Windows by allowing Node’s spawn calls in the Studio startup script to resolve shell commands such as npx.cmd.

Changes:

  • Adds shell: true to the shared spawnCommand options used for launching Vite and Electron Vite.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ivan-ottinger ivan-ottinger requested a review from a team May 27, 2026 12:33
Copy link
Copy Markdown
Contributor

@fredrikekelund fredrikekelund left a comment

Choose a reason for hiding this comment

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

Works great 👍 Thanks for fixing this, @ivan-ottinger

@fredrikekelund fredrikekelund enabled auto-merge (squash) May 29, 2026 17:00
@wpmobilebot
Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 32a0ab5 vs trunk

app-size

Metric trunk 32a0ab5 Diff Change
App Size (Mac) 1336.16 MB 1336.16 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 32a0ab5 Diff Change
load 1749 ms 1717 ms 32 ms ⚪ 0.0%

site-startup

Metric trunk 32a0ab5 Diff Change
siteCreation 9036 ms 9038 ms +2 ms ⚪ 0.0%
siteStartup 4387 ms 4378 ms 9 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@fredrikekelund fredrikekelund merged commit 7f2cd80 into trunk May 29, 2026
11 checks passed
@fredrikekelund fredrikekelund deleted the stu-1761-fix-windows-npm-start-enoent branch May 29, 2026 17:44
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.

4 participants