question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebSocket connection to 'ws://localhost:3000/ws' failed:

See original GitHub issue

Basic React App doesn’t work because the websocket connection appears to be hardcoded to port 3000. Part of this appears to be related to running in a container, but I’ve discovered additional issues even when running local.

Example project here - https://github.com/Fosol/bug-hot-reload

npm: 7.24.0 yarn: 1.22.5 node: v16.10.0 react-scripts: 5.0.0

I have cleared node_modules and performed all the mentioned steps.

Error message here.

WebSocket connection to 'ws://localhost:3000/ws' failed:

If I use port 3000 the error disappears, but nothing works.

Environment

System: OS: Windows 10 10.0.19044 CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor Binaries: Node: 16.10.0 - C:\Program Files\nodejs\node.EXE Yarn: 1.22.5 - C:\Program Files (x86)\Yarn\bin\yarn.CMD npm: 7.24.0 - C:\Program Files\nodejs\npm.CMD Browsers: Chrome: 96.0.4664.110 Edge: Spartan (44.19041.1266.0), Chromium (96.0.1054.57) Internet Explorer: 11.0.19041.1202 npmPackages: react: 17.0.2 => 17.0.2 react-dom: 17.0.2 => 17.0.2 react-scripts: 5.0.0 => 5.0.0 npmGlobalPackages: create-react-app: Not Found

Steps to reproduce

  1. Clone repo - https://github.com/Fosol/bug-hot-reload
  2. Run command docker-compose up -d
  3. Open browser http://localhost:5000

Expected behavior

Application should work and hot reload should work.

Actual behavior

Application doesn’t work and hot reload doesn’t work. Additionally, it requires rebuilding the image to get any changes. A refresh doesn’t work.

Reproducible demo

Repo here - https://github.com/Fosol/bug-hot-reload

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:25
  • Comments:54 (4 by maintainers)

github_iconTop GitHub Comments

35reactions
esetnikcommented, Dec 20, 2021

I was able to work around this issue by manually specifying the port used in my .env file:

WDS_SOCKET_PORT=443

See https://create-react-app.dev/docs/advanced-configuration/#:~:text=for more details.-,WDS_SOCKET_PORT,-✅ Used

31reactions
raixcommented, Dec 20, 2021

WDS_SOCKET_PORT=0 Will use window location, still think its a misconfig in CRA but I’ll check history in wds server to look for other clues

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket connection to 'ws://localhost:3000/' failed
The confusion starts here: const server = express();. The express function doesn't really return a server, it returns an application.
Read more >
WebSocket connection to 'ws://localhost:4000/graphql' failed
Hi, I am running into an issue on my front-end (Vue 2) when trying to connect to the web socket. I've tried several...
Read more >
WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >
Introduction | Socket.IO
Socket.IO is a library that enables low-latency, bidirectional and event-based communication between a client and a server. Diagram of a ...
Read more >
Error with WebSocket - Microsoft Q&A
Crome gives the error: WebSocket connection to 'wss://localhost:54970/Dashboard.Server/' failed: Error in connection establishment: net:: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found