webpack: "Uncaught Error: [HMR] Hot Module Replacement is disabled." appearing when adding special entry point
I’m using webpack for tota11y and absolutely loving it, but I keep running into a problem with HMR and my config.
Following the instructions at http://webpack.github.io/docs/webpack-dev-server.html#hot-mode, I’ve added webpack/hot/dev-server
as an entry point. Running
webpack-dev-server --hot
Everything works as expected, but the problem comes when I build with webpack -p
. In doing so, I get the following error when running my bundle in a browser:
Uncaught Error: [HMR] Hot Module Replacement is disabled.
Grepping through my bundle I can see that error message, but why is this hot reloading code in my bundle?
I’ve since removed that bit from the entry field in my config, and hot reloading seems to work fine. So I remain a bit confused: do I not actually need webpack/hot/dev-server
in my config? Are the docs outdated?
I checked around for this error but couldn’t find anything, so perhaps my problem runs deeper than that.
About this issue
- Original URL
- State: closed
- Created 9 years ago
- Reactions: 2
- Comments: 29 (4 by maintainers)
Commits related to this issue
- Hot reload fixed https://github.com/webpack/webpack/issues/1151 — committed to happylynx/pmgr by deleted user 8 years ago
- fix: Specify --inline and --hot options on CLI This doesn't work as devServer options. https://github.com/webpack/webpack/issues/1151 — committed to Beaglefoot/fcc-react-typescript-boilerplate by Beaglefoot 7 years ago
- chore(webpack): move dev-server options from config to CL parameters, see: https://github.com/webpack/webpack/issues/1151#issuecomment-138809417 — committed to SOCR/SOCRAT by alxndrkalinin 7 years ago
Hot Module Replacement is disabled.
means theHotModuleReplacementPlugin
is not used.--hot
adds it. (because the CLI have access to your webpack configuration)hot: true
doesn’t add it. (because the API doesn’t have access to your webpack configuration)The docs are wrong… 😢
Just use
webpack-dev-server --hot --inline
and don’t anything special about webpack-dev-server or HMR to your webpack.config.js.You have to push
new webpack.HotModuleReplacementPlugin()
this into your plugins config, webpack-dev-server when used with nodejs api do not add it automaticallyI’m getting the same, I had:
in my
webpage.config.js
and was getting errors when runningwebpack-dev-server
. However, runningwebpack-dev-server --hot --inline
makes everything work as expected.just add the plugin into the webpack config file like this:
and thanks @mailaneel
I have following in the config:
The browser shows following log:
Running
webpack-dev-server
with--hot --inline
does also not help.See this note in the docs
There are two options to fix it:
Option 1) add
new webpack.HotModuleReplacementPlugin()
to yourplugins
array in your webpack configOption 2) pass the
--hot
command line option when launchingwebpack-dev-server
I am seeing this error as well. Passing
--hot --inline
to the command line fixes it.The year is 2019, still when trying to set up dev-server and HMR following the documentation, I’ve stumbled upon this issue.
The explanation and actual behavior (when
hot
andinline
options work only through the CLI, but not through the config) is extremely weird and counter-intuitive for people not familiar with how things work internally.Could we remedy the situation somehow?
We should at least update the documentation to explain this more clearly. It’s really bad when new user have to read through the issues in order to configure a pretty basic set up.
I was getting the error until I removed the
hot: true
from my config. Unfortunately now I’m looking for a good way to disable the effect of adding thenew webpack.HotModuleReplacementPlugin()
to the loaders array. I may just extract the array and build it before exporting the webpack config module.Edit: I just javascripted my problem away. The webpack2 docs do a better job of explaining what options are CLI-only, and what
inline
does etc.I’m getting this error as well.
In response to https://github.com/webpack/webpack/issues/1151#issuecomment-343800515 and https://github.com/webpack/webpack/issues/1151#issuecomment-453764353, I actually need to do both:
new webpack.HotModuleReplacementPlugin()
to myplugins
array in my webpack config--hot
command line option when launchingwebpack-dev-server
.Also, I find it strange that I cannot use
devServer: {hot: true}
ordevServer: { hotOnly: true}
inwebpack.config.js
(it refuses to the load the webpage in the first place). This seems to contradict the documentaiton which appears to say that thatdevServer: {hot: true}
and--hot
are the same.So, I had the
new webpack.HotModuleReplacementPlugin()
line in my plugins array, but I found HMR wasn’t working (throwing[HMR] Hot Module Replacement is disabled
error) unless I passed the--hot --inline
options in the CLI. I moved the HMR Plugin to be the first in the plugins array, and now it works without the CLI options! So for anyone that sees this, try that if it’s not working for you.@mailaneel Thanks!+1
I change from devServer stuff on the webpack config into --hot --inline in the CLI command and works perfectly. Also, using a express and handling the webpack config works too…
Thanks so much for this - hours wasted here trying to figure out why live reload wasn’t working…
I tried some methods but didn’t work ,zzz
perfectly solved my problem
I bumped in similar issue. Wondering why the build file is expecting HMR. This is what i see in console while using the build file
My config file
My
package.json
scriptsHere is my webpack config. I have following folder structure:
I am compiling start.js in ‘src’ folder to ‘script.js’ in ‘build/js’ folder.
Running it with webpack is compiling exactly as I intended, however running webpack-dev server as:
is not doing as intended. However, in terminal it is showing compilation.
@mailaneel Thanks! Your solution works!