webpack-dev-server: HMR not working with multiple entries
- Operating System: Linux
- Node Version: 14.14.0
- NPM Version: 6.14.7
- webpack Version: 5.2.0
- webpack-dev-server Version: 3.11.0
- Browser: Google Chrome
- This is a bug
- This is a modification request
Code
https://github.com/slightlyfaulty/webpack-hmr-multi-entry-repro
// webpack.config.js
...
entry: {
first: ['./src/first.js', './src/first.css'],
second: ['./src/second.js', './src/second.css'],
},
...
Expected Behavior
After starting the dev server, hot module replacement should work for all JS and CSS files from all webpack entries.
Actual Behavior
Hot module replacement doesn’t work for all entries. Only files from the second entry are hot reloaded when changed. Files from the first entry do not get hot reloaded when changed.
For Bugs; How can we reproduce the behavior?
- Clone repro then
yarn && yarn start
- Open http://localhost:8080/
- Change
src/first.js
andsrc/first.css
- notice they are not hot reloaded - Change
src/second.js
andsrc/second.css
- notice they are hot reloaded
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 42
- Comments: 58 (16 by maintainers)
Commits related to this issue
- bump webpack to fix: webpack/webpack-dev-server#2792 — committed to oasisprotocol/oasis-sdk by ptrus 3 years ago
- bump webpack to fix: webpack/webpack-dev-server#2792 — committed to oasisprotocol/oasis-sdk by ptrus 3 years ago
- fix(core): hmr issue on dev (#5006) I suspect HMR does not working properly on dev because we have multiple entries. One relative issue: https://github.com/webpack/webpack-dev-server/issues/2792/ I ... — committed to toeverything/AFFiNE by pengx17 7 months ago
- fix(core): hmr issue on dev (#5006) I suspect HMR does not working properly on dev because we have multiple entries. One relative issue: https://github.com/webpack/webpack-dev-server/issues/2792/ I ... — committed to toeverything/AFFiNE by pengx17 7 months ago
- fix(core): hmr issue on dev (#5006) I suspect HMR does not working properly on dev because we have multiple entries. One relative issue: https://github.com/webpack/webpack-dev-server/issues/2792/ I ... — committed to toeverything/AFFiNE by pengx17 7 months ago
- fix(core): hmr issue on dev (#5006) I suspect HMR does not working properly on dev because we have multiple entries. One relative issue: https://github.com/webpack/webpack-dev-server/issues/2792/ I ... — committed to toeverything/AFFiNE by pengx17 7 months ago
- PR1 (#1) * fix: prettier issue * feat(core): confirm before cancel in billing page (#4749) * feat: bump up blob size limit temporarily (#4747) * ci: bump cloudflare/wrangler-action from 3.3.... — committed to adeelahmad/AFFiNE by adeelahmad 7 months ago
@slightlyfaulty setting
optimization.runtimeChunk: "single"
fixed the problem for me.@khelkun I recently discovered that if you use the dependOn option for an entry, then it will use the runtime that’s embedded in the entry it depends on.
In this case you don’t need to use
runtimeChunk: 'single'
anymore, as long as thedependOn
entry is always loaded first.@slightlyfaulty Found solution:
Exactly the same problem and same warnings as @onetrev on webpack 5.9.18 On 4.46 HMR for multiple entries works fine.
HI, @alexander-akait
for HMR not working with multiple entries
i upgrade webpack-dev-server fromv4.0.0-rc.1
tov4.0.0
it will infinite loop for update.json 404. i use"webpack": "^5.50.0",
BTW:webpack-dev-server@4.0.0-rc.1
with webpack@^5.50.0it work fine.
webpack-dev-server@4.0.0with webpack@^5.50.0
was broken, infinite loop for update.json@sokra If it’s not possible in Webpack 5 then fair enough. I think there are just a lot of people, like myself, who were doing this in Webpack 4 and it worked perfectly out the box.
Perhaps this limitation of Webpack 5 should be added to the migration guide if it isn’t already.
I also encountered this issue with multiple entries. However setting
optimization.runtimeChunk: "single"
didn’t work. I’m using multipleHtmlWebpackPlugin
s to serve the entries as solo applications. What is the best step for now? Move back towebpack@4.46.0
?Thanks for the tip @MohsenElgendy, but it’s still not really ideal as you need to then load the
runtime
chunk alongside your other bundles. Webpack 4 handled embedding the runtime in multiple bundles at the same time no problem.@chenwenqin Can you provide reproducible example?
You can’t use multiple entries on the same page, please use https://github.com/webpack/webpack-dev-server/issues/2792#issuecomment-806983882
@alexander-akait The problem I was having looks to be fixed in 4.2.1. Thank you!
Imported modules are initialized for each runtime chunk separately, so if you include multiple entry points on a page, beware of this behavior. You will probably want to set it to single or use another configuration that allows you to only have one runtime instance. From https://webpack.js.org/configuration/optimization/#optimizationruntimechunk.This method helped me solve the problem.
Other idea - output the warning in runtime and provide example how to fix it for better DX
Please test https://github.com/webpack/webpack-dev-server/releases/tag/v4.0.0-beta.1, we will speed up releases, to be stable at the end of month
I can also confirm optimization.runtimeChunk: “single” fixed the problem for me handling multiple bundles.
webpack.dev.config
webpack.common.js