Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Anoesj opened this issue Sep 9, 2024 · 2 comments
Open

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

Anoesj opened this issue Sep 9, 2024 · 2 comments

Comments

@Anoesj
Copy link

Anoesj commented Sep 9, 2024

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: [email protected]
  • 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

@Anoesj Anoesj changed the title Nitro with bun preset can't connect to websocket during dev Nitro with bun preset can't connect to WebSocket during development Sep 9, 2024
@HigherOrderLogic
Copy link
Contributor

I think it has something to do with crossws, as in the dev and node preset, Nitro is importing the one with Node adapter, not Bun.

@rschmied
Copy link

I was commenting on #1010 which is pretty similar to what I am running into. The repro there with the latest code (I had to update) and when running with bun did reproduce the error. With some changes to the dev-server/server.ts code I got it to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants