Next v12 upgrade: WebSocket connection to 'wss://localhost:3000/_next/webpack-hmr' failed: for https connections
See original GitHub issueWhat 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:
- Created 2 years ago
- Reactions:7
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@alexmarioru For me, it was occuring becauase I had set
assetPrefix
ashttp://localhost:3000
and deployment was run viahttps://dev.abcd.com
(this will make the protocol secure,wss://
). When this is done, the the Websocket URL becomeswss://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 theassetPrefix
innext.config.js
tohttps://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.
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.