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.

Next v12 upgrade: WebSocket connection to 'wss://localhost:3000/_next/webpack-hmr' failed: for https connections

See original GitHub issue

What version of Next.js are you using?

12.0.3

What version of Node.js are you using?

14.17.6

What browser are you using?

Chrome

What operating system are you using?

macOS

Describe the Bug

Post v12.0.3 migration, when I try to run the application locally via https URL, https://dev.abcd.com:443; it throws the error WebSocket connection to 'wss://localhost:3000/_next/webpack-hmr' failed.

http://localhost:3000 was set as assertPrefix.

However, It works fine when I try to use http URL, http://dev.abcd.com:3000


After digging a bit I found that, the cause was that the websocket connections for ws://localhost:3000/_next/webpack-hmr worked well, but wss://localhost:443/_next/webpack-hmr failed. I can’t figure out why secure connections are failing

#30491 did not help as I’m neither using nginx, nor a custom express server.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
neeraj3029commented, Nov 9, 2021

@alexmarioru For me, it was occuring becauase I had set assetPrefix as http://localhost:3000 and deployment was run via https://dev.abcd.com (this will make the protocol secure, wss://). When this is done, the the Websocket URL becomes wss://localhost:3000/_next/webpack-hmr.

Here, the protocol is wss:// which is a secured websocket protocol. Hence, the websocket connection will fail as localhost:3000 works only in unsecured medium.

TL;DR You should either run the local deployment via http://localhost:3000, or set the assetPrefix in next.config.js to https://dev.abcd.com/.

Refer Line 35: https://github.com/genetschneider/next.js-1/blob/e4085069e4a54373d765d1aeca5e71f80020e22b/packages/next/client/dev/error-overlay/websocket.ts#L35


@timneutkens , My recommendation would to determine the websocket protocol based on assetPrefix and not on the browser location’s protocol.

0reactions
balazsorban44commented, Jan 28, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebSocket connection failed: Error during ... - Stack Overflow
Socket.io uses a poll to connect initially then "upgrades" to more reliable transports (i.e. websockets). This answer forces socketio to only ...
Read more >
Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >
Error with WebSocket - Microsoft Q&A
Hello I get the error: WebSocket connection to 'wss://localhost:54970/Dashboard.Server/' failed: Error in connection establishment: net:: ...
Read more >
How to resolve the error: "Could not open websocket connection
How to resolve the error: “Could not open websocket connection: websocket: could not find connection header with token 'upgrade'” · The JFrog ...
Read more >
Protocol upgrade mechanism - HTTP - MDN Web Docs - Mozilla
Note: You can also use the "wss://" URL scheme to open a secure WebSocket connection. If you need to create a WebSocket connection...
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