nitrojs / nitrojs/nitro

Nitro with `bun` preset can't connect to WebSocket during development

Open
#2,721 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug nuxt v2
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.