[!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+267afa293Platform: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.
Environment
Build Modules: -
Reproduction
https://github.com/Anoesj/nitro-bun-websocket-issue
Describe the bug
I'm trying to get WebSockets to work in a Nuxt application. I've turned on
nitro.experimental.websocket
innuxt.config.ts
and I'm using thebun
Nitro preset.During development (
bun --bun run dev
), the WebSocket'sonopen
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 presetbun
andnode-server
.bun
bun
node-server
node-server
bun
bun
node-server
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