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

npm ws package overridden by broken baked-in module #2955

Closed
thislooksfun opened this issue May 19, 2023 · 3 comments · Fixed by #2934
Closed

npm ws package overridden by broken baked-in module #2955

thislooksfun opened this issue May 19, 2023 · 3 comments · Fixed by #2934
Labels
bug Something isn't working

Comments

@thislooksfun
Copy link
Contributor

thislooksfun commented May 19, 2023

What version of Bun is running?

0.6.2

What platform is your computer?

Darwin 22.4.0 x86_64 i386

What steps can reproduce the bug?

Here is a minimal example file:

import WebSocket from "ws";

const wss = new WebSocket.Server({ port: 3000 });

wss.on("connection", ws => {
  console.log("connection");
  ws.send("Hello world");
  ws.close();
});

wss.on("listening", () => {
  console.log("listening");
});

console.log("Started WebSocket server (?)");

When this file is run with Node it requires that the ws package is installed, and when it is run it outputs

Started WebSocket server (?)
listening

And attempts to connect to it succeed.

Running the same file with Bun works even without the ws package installed, and produces the output

Started WebSocket server (?)

And it does not accept any connections.

What is the expected behavior?

I would expect that if I install the ws package then Bun should use the ws package, and if it is going to override that then the replacement should at least be compatible and functional.

What do you see instead?

No response

Additional information

Yes I know that Bun.serve can do websockets, but I'm trying to use a different package that itself uses ws under the hood, and I don't want to have to rewrite that whole package just to make it work with Bun's idiosyncrasies.

@thislooksfun
Copy link
Contributor Author

I see there is a PR up to fix this, but is there any way I can work around this in the meantime? Is there any way for me to tell Bun to just load the ws package from node_modules instead of using the built-in version?

@thislooksfun
Copy link
Contributor Author

@Jarred-Sumner @cirospaciari I just updated from 0.6.2 to v0.6.3 and it's still broken. Running the above code in Node produces a stable WebSocket server that I can connect to. Running the same code in Bun 0.6.3 logs "Started WebSocket server (?)" and immediately exits. Even if I introduce an artificial delay to keep it from exiting (setTimeout(() => {}, 60_000)) it still never logs "listening" or "connection", and attempts to connect with a client fail with WebSocket connection to 'ws://<address>:<port>/' failed: There was a bad response from the server.

Is there really no way I can just use the ws package from node_modules? Why is Bun overriding this 3rd-party package anyway?

@PaddeK
Copy link

PaddeK commented Jul 11, 2023

Due to the missing exports for ping/pong in Bun.serve i tried to use ws as fallback until Bun.serve is fixed.
I am using Bun 0.6.13 on Darwin 22.5.0 x86_64 i386 and this problem still persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants