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.

HMR not working when ssl is activated

See original GitHub issue

Describe the bug

After enabling HTTPS I noticed the log message Firefox can't establish a connection to the server at ws://localhost:3000/sockjs-node. in the browser console. Also i noticed Hot Module Reloading not working.

I assume instead of the WS the WSS protocol should be used when using HTTPS? I am not sure if this is an issue with webpack?

Did you try recovering your dependencies?

Yes npm version: 6.11.3

Which terms did you search for in User Guide?

HMR, HTTPS, SSL, WS, sockjs-node not found

Environment

System: OS: Windows 10 10.0.18362 CPU: (8) x64 Intel® Core™ i7-7700HQ CPU @ 2.80GHz Binaries: Node: 12.4.0 - C:\Progra~1\nodejs\node.EXE Yarn: Not Found npm: 6.11.3 - C:\Progra~1\nodejs\npm.CMD Browsers: Edge: 44.18362.449.0 Internet Explorer: 11.0.18362.1 npmPackages: react: ^16.12.0 => 16.12.0 react-dom: ^16.12.0 => 16.12.0 react-scripts: ^3.3.0 => 3.3.0 npmGlobalPackages: create-react-app: Not Found

Steps to reproduce

  1. npx create-react-app my-app --template typescript
  2. add file .env to project root with content HTTPS=true
  3. run the app
  4. open browser console and / or edit code files

Expected behavior

HMR would work as before (without HTTPS) and no message about unreachable ws://localhost:3000/sockjs-node endpoints

Actual behavior

In the browser console the message below is displayed and HMR is not working

chrome: WebSocket connection to 'ws://localhost:3000/sockjs-node' failed: Connection closed before receiving a handshake response (webpackHotDevClient.js:60)

firefox: Firefox can't establish a connection to the server at ws://localhost:3000/sockjs-node. (webpackHotDevClient.js:60)

Reproducible demo

same as Steps to reproduce

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

5reactions
saikatguhacommented, Dec 14, 2019

Changing the Line 62 in ./node_modules/react-dev-utils/webpackHotDevClient.js to protocol: 'wss' gets it working again:

var connection = new WebSocket(
  url.format({
    protocol: 'wss',   // <---- Changed from 'ws' to 'wss'
    hostname: window.location.hostname,
    port: window.location.port,
    // Hardcoded in WebpackDevServer
    pathname: '/sockjs-node',
    slashes: true,
  })
);

1reaction
danielkczcommented, Dec 14, 2019

I can confirm the same behavior for Chrome 78.

There is also implication you don’t mention here, the browser won’t even refresh on change, so it’s fairly annoying to be refreshing manually. Not sure if Firefox somehow works better on that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

HMR loop reboot with .Net Core 2.1.2 + Angular 6 when Https ...
//https app.UseHttpsRedirection(); app.UseHsts();. Then I enabled SSL option in the properties of my projet in the tab "debug". The api works ...
Read more >
Laravel Mix HMR with HTTPS | Codecourse Blog
I use Laravel Valet for day-to-day development, and I recently got stuck getting Laravel Mix HMR (Hot Module Replacement) to work while I...
Read more >
Solution for Webpack 5 Dev Server Not Live Reloading
There is currently a bug with Webpack 5 and webpack-dev-server not working that is caused by the existence of a browserslist in the...
Read more >
ng serve - Angular
Option Description Value Type Default Value ‑‑hmr Enable hot module replacement. boolean false ‑‑host Host to listen on. string localhost ‑‑open Opens the url in default...
Read more >
DevServer - webpack
<i> [webpack-dev-server] Project is running at: <i> [webpack-dev-server] Loopback: ... Content not from webpack is served from '/path/to/public' directory.
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