You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
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.
changed the title [-]HMR/Live Reloading broken after Webpack 5 beta.33 -> rc.3 update[/-][+]HMR/Live Reloading broken after Webpack 5 rc.0 -> rc.1 update[/+]on Oct 6, 2020
Interestingly, removing .browserlistrc seems 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.js ends with:
/******//************************************************************************//******/// module cache are used so entry inlining is disabled/******/// startup/******/// Load entry module/******/__webpack_require__("./src/index.jsx");/******/__webpack_require__("./node_modules/webpack/hot/dev-server.js");/******/})();
and without .browserlistrc (no: when HMR is working), src.js ends with:
/************************************************************************//******/// module cache are used so entry inlining is disabled/******/// startup/******/// Load entry module/******/__webpack_require__("./src/index.jsx");/******/__webpack_require__("./node_modules/webpack-dev-server/client/index.js?http://localhost:3000");/******/__webpack_require__("./node_modules/webpack/hot/dev-server.js");/******/})();
Reacted by Michał Grzegorzewski, alex-kim-dev, L.Rain, Latif Sulistyo, dongliang, Mikhail Fedosov, Charles, Pierre Lebedel, Pavel L., Pablo Grillo and 30 more
Reacted by Vladimir Lila
Reacted by Da-Woon Chung, Mikhail Fedosov, Jan Greger Hemb, momo, J.Fischer and Willian Schenkel
@evilebottnawi looks like your diagnosis is correct, because adding target: 'web' (which overwrites the default being 'browserlist' since 5.0.0-rc.1) to Webpack config resolves the issue.
Reacted by Tobias Graf, Andrey, Pascal Loth, Michał Grzegorzewski, alex-kim-dev, Gavin Lloyd, Pierre Lebedel, 沉浸式~~, Kévin Painchaud, Benoît Burgener and 21 more
…to the base webpack config, that the latest release does indeed work.
Reacted by Argel Enriquez, Andrey, Alexey Slobodyansky, Neal Granger, Heiko, Liam Chapman, Anton Prasolov, Václav Jančařík, lostguk, JingLv-ND and 30 more
Reacted by Guilherme Teixeira Batista, Fabian Hippmann, kisekiremi, zcoder and Marcos de Andrade
Reacted by Vladimir Lila, Fabian Hippmann, Theo Avoyne, kisekiremi and Marcos de Andrade
I've pushed a pull request to fix it, can anyone with the problem try the branch with yarn's resolution? Just adding the below code to package.json and run yarn install --force
webpack_1 | > webpack-dev-server --config webpack.dev.js --trace-deprecation
webpack_1 |
webpack_1 | Error: Cannot find module '../../client/'
webpack_1 | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:668:15)
webpack_1 | at Function.resolve (internal/modules/cjs/helpers.js:19:19)
webpack_1 | at addEntries (/var/www/project/buildchain/node_modules/webpack-dev-server/lib/utils/addEntries.js:39:36)
webpack_1 | at updateCompiler (/var/www/project/buildchain/node_modules/webpack-dev-server/lib/utils/updateCompiler.js:48:5)
webpack_1 | at new Server (/var/www/project/buildchain/node_modules/webpack-dev-server/lib/Server.js:72:5)
webpack_1 | at startDevServer (/var/www/project/buildchain/node_modules/webpack-dev-server/bin/webpack-dev-server.js:106:14)
webpack_1 | at processOptions (/var/www/project/buildchain/node_modules/webpack-dev-server/bin/webpack-dev-server.js:166:3)
webpack_1 | at findPort.then (/var/www/project/buildchain/node_modules/webpack-dev-server/lib/utils/processOptions.js:33:9)
webpack_1 | at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:52:5)
webpack_1 | at Function.Module.runMain (internal/modules/cjs/loader.js:880:11)
webpack_1 | at internal/main/run_main_module.js:21:11
webpack_1 | npm ERR! code ELIFECYCLE
webpack_1 | npm ERR! errno 1
webpack_1 | npm ERR! example-project@1.1.3 debug: `webpack-dev-server --config webpack.dev.js --trace-deprecation`
webpack_1 | npm ERR! Exit status 1
webpack_1 | npm ERR!
webpack_1 | npm ERR! Failed at the example-project@1.1.3 debug script.
webpack_1 | npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
webpack_1 |
webpack_1 | npm ERR! A complete log of this run can be found in:
webpack_1 | npm ERR! /root/.npm/_logs/2020-10-12T05_14_22_391Z-debug.log
fwt_webpack_1 exited with code 1
Sorry, have no idea what's going on here. Maybe you can remove the resolution and try to edit node_modules/webpack-dev-server/lib/utils/addEntries directly? Just add a browserslist in the webTarget array. I've tested on my computer with the example code @wojtekmaj provides, it seems to be working fine with both webpack 5.0.0-rc.3 and webpack 5.
@alexander-akait Ha ok I understand. Glad to share interesting use case with webpack team 🍻😉 I will follow the associated issue, just let me know if you still need access to the repository because it will evolve in the near weeks. Thanks!
Sure thing @alexander-akait thank you for offering your help. Please see below for a link to the repo. The app itself doesn't do anything yet. I've been focused on setting up the environment first before adding any functionality. The issue I'm running into is that when I change the text content inside of App.tsx, the change is only reflected after manually re-building bundle.
The hierarchy is as follows: index.tsx renders App.tsx, which only includes a single div with some inner HTML. Feel free to ignore the Context provider for the time being as well as the testing suite. There is also a server.ts file which handles the back end inside the server directory. To get started - npm install, npm run build, and then npm run dev.
You proxy all request to your server, you need keep, for example:
// Only HTML passed to your serverproxy: {"/": {target: `http://localhost:${process.env.SERVER_PORT}`,secure: false,bypass: function(req,res,proxyOptions){if(req.headers.accept.indexOf('html')!==-1){console.log('Skipping proxy for browser request.');return'/index.html';}},},},
Also not you need to add build/index.html - <div id="root"></div>
If your requests are overlapping, i.e. you have /public/image.png for main server and /public/image.png for dev server, hard to say what is the better for you, I think you need handle only html based requests
Activity
[-]HMR/Live Reloading broken after Webpack 5 beta.33 -> rc.3 update[/-][+]HMR/Live Reloading broken after Webpack 5 rc.0 -> rc.1 update[/+]alexander-akait commentedon Oct 6, 2020
Please create reproducible test repo, I think bug in
webpack-dev-serverwojtekmaj commentedon Oct 6, 2020
Managed to narrow it down quite a lot.
Webpack HMR bug repro.zip
wojtekmaj commentedon Oct 6, 2020
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:alexander-akait commentedon Oct 6, 2020
@wojtekmaj Can you provide
.browserlistrc?alexander-akait commentedon Oct 6, 2020
Looks webpack-dev-server thinks it is not browser
wojtekmaj commentedon Oct 6, 2020
An example is in the repro repo linked above, but I tested these and all of them broke the build for me:
Original:
Original but lowercase:
Thought it's maybe IE so removed and left just Chrome:
wojtekmaj commentedon Oct 6, 2020
@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.alexander-akait commentedon Oct 6, 2020
Yes, we need to fix it in webpack-dev-server, hope I will find time on it, anyway you can send a PR
khalwat commentedon Oct 12, 2020
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:
khalwat commentedon Oct 12, 2020
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.
chenxsan commentedon Oct 12, 2020
I've pushed a pull request to fix it, can anyone with the problem try the branch with yarn's resolution? Just adding the below code to
package.jsonand runyarn install --forcekhalwat commentedon Oct 12, 2020
Using that @chenxsan I get:
chenxsan commentedon Oct 12, 2020
Sorry, have no idea what's going on here. Maybe you can remove the resolution and try to edit
node_modules/webpack-dev-server/lib/utils/addEntriesdirectly? Just add abrowserslistin thewebTargetarray. I've tested on my computer with the example code @wojtekmaj provides, it seems to be working fine with both webpack 5.0.0-rc.3 and webpack 5.fix: Force webpack target to web
74 remaining items
xavierfoucrier commentedon Sep 4, 2021
@alexander-akait Ha ok I understand. Glad to share interesting use case with webpack team 🍻😉 I will follow the associated issue, just let me know if you still need access to the repository because it will evolve in the near weeks. Thanks!
alexander-akait commentedon Sep 4, 2021
@xavierfoucrier yep, I will ping you if will need more information (but I have local version)
dbehmoaras commentedon Sep 7, 2021
having the same issue. tried every single fix mentioned here and still no luck......
alexander-akait commentedon Sep 8, 2021
@dbehmoaras Please provide reproducible test repo
dbehmoaras commentedon Sep 8, 2021
Sure thing @alexander-akait thank you for offering your help. Please see below for a link to the repo. The app itself doesn't do anything yet. I've been focused on setting up the environment first before adding any functionality. The issue I'm running into is that when I change the text content inside of App.tsx, the change is only reflected after manually re-building bundle.
https://github.com/ResearchGlobal/stockwatch
The hierarchy is as follows: index.tsx renders App.tsx, which only includes a single div with some inner HTML. Feel free to ignore the Context provider for the time being as well as the testing suite. There is also a server.ts file which handles the back end inside the server directory. To get started - npm install, npm run build, and then npm run dev.
alexander-akait commentedon Sep 8, 2021
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>dbehmoaras commentedon Sep 8, 2021
@alexander-akait thank you very much. I will try this right away and let you know if it helps.
dbehmoaras commentedon Sep 8, 2021
@alexander-akait worked like a charm! Thank you very much for your help! I am very grateful
dbehmoaras commentedon Sep 8, 2021
@alexander-akait quick follow up - if i add a proxy, is it correct to assume that i would need to add the bypass in the same way?
alexander-akait commentedon Sep 8, 2021
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 requestsdbehmoaras commentedon Sep 8, 2021
ok that makes sense, thanks!
Jingotto commentedon Nov 12, 2021
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.
vaibhav023 commentedon Nov 17, 2021
CHENJIAMIAN commentedon Apr 20, 2022
use cnpm install , resolve.symlinks: false, make it happen.
You can see this troubleshooting.html#symbolic-links-in-node-modules
amrfhn commentedon Aug 4, 2022
Hello, i come from 2022, is there any updates regarding the live reloading issue?