Open caleniuc opened 5 years ago
That's not related to react-hot-loader, as long as that purely webpack related problem. But anyway:
webpack-hot-middleware
should be first, but better remove itHotModuleReplacementPlugin
, but better don't use itWhat shall you do?
NODE_ENV=development webpack-dev-server --hot
, and THAT'S ALL.Bonus: The real problem is displayed next to
[HMR] The following modules couldn't be hot updated: (Full reload needed)
Which file and WHY it could not be updated - that's, that's something you should think about. For example you might have two webpack-hot-middlewares
.
If i remove webpack-hot-middleware then changes are no more detected in the browser, also if I put it in the first position in entry the issue persists.
I do have the HotModuleReplacementPlugin, but forgot to insert it in the config here.
We use express + webpack-dev-middleware.
For every .js file this happens, if I modify Tile.js then the message appears in console for this file that I've modified.
I'll try to search more into the documentation of webpack and maybe open an issue there.
Thank you for your answer! :)
express
+ webpack-dev-middleware
is a very fragile combination, it's easy to get it right, but also easy to break everything.
I would try to create an example, as long as right now there is no example, and this is a popular issue.
If you will find the answer before me - feel free to post it here.
what is the proper way to setup hot reload in webpack?
That's a complex theoretical problem, but there are 2 rules:
/root
helper does for you)I too, was using express
+ webpack-dev-middleware
and was getting The following modules couldn't be hot updated
.
This blog post worked out for me: https://medium.com/@larrybotha/great-article-4d0eb79a61a6#_=_
Solution (Add to client side entry file):
if (module && module.hot && module.hot.accept) {
module.hot.accept()
}
@songz - this is something you should not do.
Proper setup for hot-loader (import { hot } from 'react-hot-loader/root';....
) will configure HMR by itself - https://github.com/gaearon/react-hot-loader/blob/6032f4255e0268bb794c1e9b8ae5b436400ffbb5/src/hot.dev.js#L102
If you doing more than you should, or not doing what README has told you.
Have a look at this repo https://github.com/tomtom94/react-easy-ssr
Using SSR split code only allows you to use import { hot } from 'react-hot-loader/root'
everwhere in your component.
Using the other solution patch as entry point won't work, because of split code.
module.exports = {
entry: ['react-hot-loader/patch', './src'],
// ...
};
If you are reporting a bug or having an issue setting up React Hot Loader, please fill in below. For feature requests, feel free to remove this template entirely.
Description
Upgraded Webpack from V2 and react-transform-hmr to Webpack V4 with react-hot-loader, but I'm getting:
Expected behavior
I'm expecting that JS files do hot reload and not require a full reload. Maybe this is an issue with my configuration, but I've tried everything so far and can't find an actual answer. Hot reload works on SCSS files, but not on JS files.
Actual behavior
Environment
React Hot Loader version: 4.12.0
Run these commands in the project folder and fill in their results:
node -v
: v8.10.0npm -v
: v5.6.0Then, specify:
webpack.config.js
Entry:
JS files loader:
.babelrc
Root component exported
export default hot(Root);