webpack-dev-server: HMR/Live Reloading broken after Webpack 5 rc.0 -> rc.1 update
- Operating System: macOS Big Sur
- Node Version: 14.5.0
- NPM Version: 6.14.5
- webpack Version: 5.0.0-rc.3
- webpack-dev-server Version: ^3.10.3
- Browser: Chrome
- This is a bug
- This is a modification request
After upgrading from Webpack 5.0.0-beta.29 to 5.0.0-rc.3, I’ve noticed that HMR/Live Reloading stopped working, even though no other changes to the code were made.
I investigated by updating it step by step and here’s my outcome:
| Version | Works? |
|---|---|
| 5.0.0-beta.29 | Yes ✅ |
| 5.0.0-beta.30 | Yes ✅ |
| 5.0.0-beta.31 | Yes ✅ |
| 5.0.0-beta.32 | Yes ✅ |
| 5.0.0-beta.33 | Yes ✅ |
| 5.0.0-rc.0 | Yes ✅ |
| 5.0.0-rc.1 | No ❌ |
| 5.0.0-rc.2 | No ❌ |
| 5.0.0-rc.3 | No ❌ |
Code
// webpack.config.js
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const isProduction = process.env.NODE_ENV === 'production';
const isDevelopment = !isProduction;
const publicPath = process.env.PUBLIC_URL || '/';
module.exports = {
mode: isProduction ? 'production' : 'development',
bail: isProduction,
entry: {
src: [
'./src/index.jsx',
],
},
output: {
path: path.resolve(__dirname, 'dist'),
publicPath,
},
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
include: path.resolve(__dirname, 'src'),
use: 'babel-loader',
},
].filter(Boolean),
},
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html'
}),
].filter(Boolean),
devServer: {
historyApiFallback: true,
hot: true,
port: 3000,
},
};
Expected Behavior
HMR to work on Webpack version 5.0.0-rc.1 to 5.0.0-rc.3.
Console output in 5.0.0-beta.29 to 5.0.0-rc.0:
[HMR] Waiting for update signal from WDS...
[WDS] Hot Module Replacement enabled.
[WDS] Live Reloading enabled.
…and of course, on change…
[WDS] App updated. Recompiling...
[WDS] App updated. Recompiling...
[WDS] App hot update...
[HMR] Checking for updates on the server...
[HMR] Updated modules:
[HMR] - ./components/pages/index.jsx
[HMR] App is up to date.
Actual Behavior
HMR doesn’t on Webpack version 5.0.0-rc.1 to 5.0.0-rc.3.
Console output in 5.0.0-rc.3:
[HMR] Waiting for update signal from WDS...
…and silence after that.
I can see that Webpack is rebuilding, so I think Webpack part works fine. Refreshing the page manually also gets me the updated page. So only HMR/Live Reloading part must be broken.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 63
- Comments: 91 (34 by maintainers)
Links to this issue
- javascript - Webpack 5 live reload - Stack Overflow
- javascript - Hot Module Replacement '[HMR] Waiting for update signal from WDS...' forever, how to enable Hot Module Replacement? - Stack Overflow
- Webpack 5 dev server does not reload on file changes - Stack Overflow
- javascript - Can't set up the HMR: stuck with "Waiting for update signal from WDS..." in console - Stack Overflow
Commits related to this issue
- fix: Force webpack target to web Also, browserslist does not seem to work here. See https://github.com/webpack/webpack-dev-server/issues/2758 — committed to sfeir-open-source/talk-control by jtanguy 4 years ago
- :bug: Fix HMR for webpack-dev-server temporarily Waiting on this issue https://github.com/webpack/webpack-dev-server/issues/2758 to be fixed — committed to TobitSoftware/chayns-toolkit by leodr 4 years ago
- fix: Temporary solution for broken HMR https://github.com/webpack/webpack-dev-server/issues/2758 — committed to pangolinjs/core by mvsde 4 years ago
- FIX - hot reload issue - https://github.com/webpack/webpack-dev-server/issues/2758 — committed to bartko-s/frontend-bootstrap by bartko-s 4 years ago
- Issue with devServer HMR fixed (https://github.com/webpack/webpack-dev-server/issues/2758) — committed to Kurdiumov/quote-of-the-day by Kurdiumov 4 years ago
- chore: fix webpack HMR ref: https://github.com/webpack/webpack-dev-server/issues/2758 — committed to zwave-js/zwave-js-ui by robertsLando 3 years ago
- chore: fix webpack HMR (#306) * chore: fix webpack HMR ref: https://github.com/webpack/webpack-dev-server/issues/2758 * fix: lint issues — committed to zwave-js/zwave-js-ui by robertsLando 3 years ago
- Fix HMR issue See `https://github.com/webpack/webpack-dev-server/issues/2758` https://www.youtube.com/watch?v=lNkVndKCum8 — committed to kalaschnik/multipurpose-webpack-config by kalaschnik 3 years ago
- fix: something error in webpack5 and webpack-dev-server when browserslist exists, it makes Live Reloading stopped working. it must be a bug, look in issues https://github.com/webpack/webpack-dev-serv... — committed to Sneaken/webpack-react by Sneaken 3 years ago
- fix: for hmr bug see https://github.com/webpack/webpack-dev-server/issues/2758 — committed to nokv/webpack-boilerplate by nokv 3 years ago
- https://github.com/webpack/webpack-dev-server/issues/2758 — committed to robisim74/nodejs-mvc by robisim74 3 years ago
Yup, the ability to set arrays as a target also came with webpack 5. Arrays are listed as a valid type in the webpack 5 docs, but not in the webpack 4 docs
EDIT: If it helps, my current fix is to specify “web” as a target when developing and “browserslist” as a target when building for production:
I can confirm that it works as expected with webpack
5.0.0-rc.0but breaks with5.0.0-rc.1so the error is here somewhere:https://github.com/webpack/webpack/compare/v5.0.0-rc.0..v5.0.0-rc.1
https://github.com/webpack/webpack/releases/tag/v5.0.0-rc.1
I can also confirm that if I add:
…to the base webpack config, that the latest release does indeed work.
this issue is still existing when you set browserlist in package.json
Interestingly, removing
.browserlistrcseems to fix the issue.So I compared src.js in both cases looking for answer and found that:
With .browserlistrc (no: when HMR not working)
src.jsends with:and without .browserlistrc (no: when HMR is working),
src.jsends with:Fixed in v4 branch (release will be soon, this week or first day of the next week)
@evilebottnawi looks like your diagnosis is correct, because adding
target: 'web'(which overwrites the default being'browserlist'since5.0.0-rc.1) to Webpack config resolves the issue.After struggling 1 day I confirm that having a
browserslistfile inside the root of the project breaks HMR.webpack5.2webpack-cli4.1webpack-dev-server3.11babel-loader8.1.0Everything was behaving as expected with webpack 4.
Forcing
target: 'web'restores the HMR functionality, even with thebrowserslistfile in place.Not sure if that helps, but it looks like this problem also occurs when the target is an array. For example:
target: 'web'works, buttarget: ['web']doesn’t.Is there any particular reason that this fix isn’t being backported to v3, especially since v4 is still in beta months later?
I also had a problem with the DevServer, the pages were not refreshed. I added this code and it helped me.
static: { directory: path.join(__dirname, ‘src’), watch: true, },
P.S. Maybe I didn’t understand the problem, sorry, i’m a noob. But if someone faced the same problem it helps.
I can confirm using target:web fixes the problem
Following the migration guide to webpack 5, it suggests setting
target: ['web', 'es5']which ended up breaking live reload: https://webpack.js.org/migrate/5/#need-to-support-an-older-browser-like-ie-11Adding “target: web” fixed it for me but unfortunately means my dev environment no longer builds for IE11 - is there a way to get both working?
remove:
It is automatically enable when
hot: true(default).to
Other note:
But the main problems is here:
You proxy all request to your server, you need keep, for example:
Also not you need to add
build/index.html-<div id="root"></div>This problem is still actual in Webpack 5.25.1. I need to combine ES5 with live reload because there are still many enterprises who supports IE 11.
No
Yep @ShevchukOleg , I have
webpack-dev-serverversion^4.0.0-beta.0up and working in my config, and it’s wonderful. It fixes thetarget: 'web'issue mentioned in this thread, too.Thank you to @alexander-akait & the whole team for your hard work on this!
Why is this closed? This still seems to be an issue.
Setting
targettowebfixed it. Setting aside the non-obvious remedy – doesn’t thebrowserslistoption basically look at the config and resolve the righttargetto use? If that’s the case I’d expect my target to resolve towebanyway and proceed as usual, so what’s the underlying issue here?We were also experiencing this to still be broken in
v4.0.0-beta.0but looks to have been fully resolved inv4.0.0-beta.1without the need to specifytarget: 'web'.Tested using webpack v5.30.0.
The problem is still present in Webpack 5.30.0. Placing this in
webpack.config.jssolves the issue:I will add that declaring
browserslistentry in yourpackage.jsonalso reproduces this. Doing thetargetworkaround for now.@xavierfoucrier here interesting case, because
hot: trueby default we are trying to apply hot replacement, but withoutwatchFilesdev server doesn’t known what change in your twig template requires live reload, for this case we implementwatchFiles, yes, webpack recompiling changestwigtemplates duetwig-html-loader, in theory we can getupdatedModulesand check if it is empty it means nothing was changed and if compilation hash was changed it means you need to reload browser, I think we can mark this as featureYou can try
beta, in near future we will do the next beta releaseHeh… Just spent 2 hours trying to trace the root cause… 🤯
I would not have guessed in a million years the browser list file was the cause.
Managed to narrow it down quite a lot.
Webpack HMR bug repro.zip
The latest stable version in npm is still
webpack-dev-server@3.11.2, and this issue was fixed in latest rc version:Looking forward to the release of the stable version of v4, thanks for your hard work 😛
@slightlyfaulty You’re right here. As of webpack v5.0.0-rc.1 https://github.com/webpack/webpack/releases/tag/v5.0.0-rc.1, the
targetdefaults tobrowserslistif you have browserslist in your project. Butwebpack-dev-serveris not updated yet to follow that change. I think that’s why client parts are not included, resulting no socket connected to the server to watch updates.I too am experiencing this issue, which renders HMR inoperative with webpack 5, though I’m using
@babel/preset-envrather than.browserlistrc.But the symptoms are the same, everything builds, but this is all that is output in the console:
I did confirm, however, that rolling back to:
causes it to work again as expected:
use cnpm install , resolve.symlinks: false, make it happen. You can see this troubleshooting.html#symbolic-links-in-node-modules
If your requests are overlapping, i.e. you have
/public/image.pngfor main server and/public/image.pngfor dev server, hard to say what is the better for you, I think you need handle onlyhtmlbased requests@alexander-akait worked like a charm! Thank you very much for your help! I am very grateful
@xavierfoucrier yep, I will ping you if will need more information (but I have local version)
@myou11 this https://webpack.js.org/configuration/other-options/#ignorewarnings, ideally you should not have warnings at all or control them by filtering
@xavierfoucrier sorry for delay, I got sick covid, but I’m already better, I’ll see tomorrow
Feel free to ping me
oh, maybe you have loader or plugin for generating or something else, if you provide reproducible step I will say you what is wrong
Also:
is invalid,
static.directory: [path.join(__dirname, 'src'), path.join(__dirname, 'wds')]is valid, but you don’t need to watchsrc, because webpack already reloads them when you do changes, for additional files (i.e. you don’t haveimport/@import/etc in your files you can usewatcFiles, glob is supported)In case it helps somebody: in our case (react app) live reloading stopped working after updating from webpack v4.30.0 to v5.30.0. After some investigations, we found that the react-hot-loader config was causing the issue, and that removing it from the project brings the reloading functionality back, loosing the Hot Reload though 😕.
Still missing some further investigations to properly identify the exact cause of the problem.
Important to mention that @gaearon has deprecated react-hot-loader, and they are moving towards a webpack plugin, still experimental: https://github.com/pmmmwh/react-refresh-webpack-plugin/
Hope that helps 😉
@rnnyrk the beta works wonderfully, you can see it in use here: https://github.com/nystudio107/annotated-webpack-config/tree/webpack-5
According to docs, “Although webpack does not support multiple strings being passed into the target property, you can create an isomorphic library by bundling two separate configurations…”
So really, using an array just breaks it, although there is no build warning to say that arrays are not accepted in the for the target attribute.
Glad I saw your comment, I was searching for hours!
Removing the target property from webpack.config.js also works fine for me for development purpose. As you said we can later add the target property when we are building for production.
@chenxsan’s fix works for me.
Seems this issue happens when you have a
browserslistentry in yourpackage.json. Modules from./node_modules/webpack-dev-server/client/are not included in the output bundle at all. After removingbrowserslist, they are included correctly.