Nitro with `bun` preset can't connect to WebSocket during development
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 11.2k
- Forks
- 899
- Avg merge
- 2d 24m
- Merged PRs (30d)
- 40
Description
Environment
- Operating System: Linux
- Node Version: v20.12.2
- Nuxt Version: 3.13.1
- CLI Version: 3.13.1
- Nitro Version: 2.9.7
- Package Manager: bun@1.1.27
- Builder: -
- User Config: compatibilityDate, devtools, nitro
- Runtime Modules: -
- Build Modules: -
Reproduction
https://github.com/Anoesj/nitro-bun-websocket-issue
[!NOTE]
I could not create a reproduction in Stackblitz/CodeSandbox, as I couldn't figure out how to use Bun there. Therefore, I created a repo instead. Make sure to read the README for reproduction steps.
Describe the bug
I'm trying to get WebSockets to work in a Nuxt application. I've turned on nitro.experimental.websocket in nuxt.config.ts and I'm using the bun Nitro preset.
During development (bun --bun run dev), the WebSocket's onopen event never fires, suggesting the connection can't be fully established, but doesn't "fail" either.
After building the app and previewing it (bun --bun run build && bun --bun run preview), the WebSocket does work.
When using the node-server Nitro preset instead, the WebSocket does not work in both development mode and after building and previewing the app.
When switching to node by omitting the --bun flag (so: bun run dev / bun run build && bun run preview), the WebSocket does work in both development mode and after building and preview the app, for both Nitro preset bun and node-server.
So all in all:
| Runtime | Mode | Nitro preset | WebSocket works? |
|---|---|---|---|
| Bun | Dev | bun |
❌ |
| Bun | Build + preview | bun |
✅ |
| Bun | Dev | node-server |
❌ |
| Bun | Build + preview | node-server |
❌ |
| Node | Dev | bun |
✅ |
| Node | Build + preview | bun |
✅ |
| Node | Dev | node-server |
✅ |
| Node | Build + preview | node-server |
✅ |
Additional context
Bun revision: 1.1.27+267afa293
Platform: Linux 6.8.0-40-generic x86_64 x86_64.
If this is a Nuxt issue, feel free to transfer the issue to the Nuxt repository.
Logs
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked reproduction repository and its README, then verify the behavior using the listed bun --bun run dev, build, and preview commands with nitro.experimental.websocket enabled. Compare the Bun development path with the working Node and build/preview cases. Done means WebSocket connections open during Bun development with the bun Nitro preset, without regressing the documented working combinations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, nuxt, typescript
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100