fix: spawn server with node on Windows to avoid Bun PTY incompatibility#28
Merged
fix: spawn server with node on Windows to avoid Bun PTY incompatibility#28
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
On Windows, two Bun-specific PTY paths fail:
- Bun.spawn({ terminal }) throws "not supported on this platform"
- @lydell/node-pty's ConPTY backend uses net.Socket({ fd }) to wrap named
pipes, which Bun's net.Socket implementation does not support on Windows,
causing pid=0 and ERR_SOCKET_CLOSED on the first write
bunx webtty already works because its #!/usr/bin/env node shim runs the
server with Node.js, where node-pty's ConPTY backend works correctly.
Mirror that explicitly in startServer: on Windows under Bun, spawn the
server process with `node` instead of process.execPath.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adjusts the CLI server startup path to avoid Bun-specific PTY incompatibilities on Windows by spawning the server under Node.js when the CLI itself is running under Bun on Windows.
Changes:
- Add Windows+Bun detection and select
nodeas the server executable instead ofprocess.execPath. - Document the rationale in
startServerwith a Windows/Bun/node-pty ConPTY explanation.
Comments suppressed due to low confidence (1)
src/cli/http.ts:70
- Switching to
serverExec = 'node'introduces a new failure mode wherespawncan fail immediately (e.g. Node not on PATH) butstartServerwill still just poll until it times out and report "server did not start in time". Add explicit handling for child process spawn errors/early exit (and ideally a clearer message like "Node.js is required on Windows when running under Bun").
const child = _spawn(serverExec, [serverEntry], {
detached: true,
stdio,
env: { ...process.env, PORT: String(PORT) },
});
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- When serverExec is `node`, always resolve to the compiled `.js` entry since Node.js cannot execute `.ts` files directly (unlike Bun) - Add a spawn `error` event handler so a missing `node` binary on PATH surfaces immediately with a clear message rather than timing out Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
Author
|
Also addressed in fdade47: added a |
- Add `on` method to fakeChild mocks in http.test.ts so startServer's new spawn error handler doesn't throw in tests - Cast process.exit to void-return type before the early return so the 'server entry not found' test path exits cleanly when exit is mocked - Replace noNonNullAssertion (session!) with optional chaining (session?) in websocket.test.ts to clear pre-existing biome lint warnings Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bun run webttydisconnected immediately in the browser whilebunx webttyworked fineBun.spawn({ terminal })throws"terminal option is not supported on this platform"@lydell/node-pty's ConPTY backend wraps named pipes usingnet.Socket({ fd }), which Bun'snet.Socketdoes not support on Windows — resulting inpid=0andERR_SOCKET_CLOSEDon the first writebunx webttyworks because its#!/usr/bin/env nodeshim runs the server process with Node.js, where node-pty's ConPTY backend works correctlystartServer, when running on Windows under Bun, spawn the server withnodeinstead ofprocess.execPath— mirroring exactly whatbunxdoes implicitlyTest plan
bun run webttyon Windows — browser opens, terminal connects and stays connectedbunx webttyon Windows — still works as beforebun run webttyon macOS/Linux — still works (condition is Windows-only)🤖 Generated with Claude Code