Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hot reload module failed : Cannot apply update. Need to do a full reload! #395

Closed
iroy2000 opened this issue Feb 1, 2016 · 16 comments
Closed

Comments

@iroy2000
Copy link

iroy2000 commented Feb 1, 2016

I was trying to debug why the HMR do full page reload everytime ...

[HMR] Cannot apply update. Need to do a full reload!

screen shot 2016-02-28 at 3 56 22 pm

And I tried to look into the module 286 and I don't know why it is not accepted ...

screen shot 2016-02-28 at 3 56 11 pm

... And I start doing some tracing ... ( Not sure if the following is useful information or not )

I found parent.hot._acceptedDependencies has nothing in it

screen shot 2016-02-01 at 12 31 34 pm

screen shot 2016-02-01 at 2 38 10 pm

And my webpack config is very common, and I used the CLI

CLI:
webpack-dev-server --hot --progress --colors --inline --content-base ./docroot

webpack config:

output: {
        path: path.join(__dirname, "docroot"),
        filename: (IS_PRODUCTION ? "assets/[hash].js" : "assets/bundle.js"),
        publicPath: "/"
    },

.
.
.

entry = [
        "webpack-dev-server/client?http://localhost:8080",
        './'+APP_ENTRY_POINT
    ];

Any help will be appreciated, thanks.


According to the documentation -- Hot Module Replacement with Inline mode on CLI

Nothing more is needed. --inline --hot does all the relevant work automatically. The CLI of the webpack-dev-server automatically adds the special webpack/hot/dev-server entry point to your configuration. #

@iroy2000 iroy2000 reopened this Feb 28, 2016
@iroy2000 iroy2000 changed the title Hot reload module failed, because of parent.hot._acceptedDependencies has nothing inside Hot reload module failed : Cannot apply update. Need to do a full reload! Feb 28, 2016
@iroy2000
Copy link
Author

iroy2000 commented Mar 1, 2016

Um, I setup another project and seems working fine.

The project that failed with "Cannot apply update. Need to do a full reload!" is using with vagrant. Wonder it could be related to the problem. Need to research more on that, but if you have any insight, please let us know too. Thanks.

@mummybot
Copy link

mummybot commented Mar 1, 2016

Are you proxying, using the iframe mode or referencing your scripts inline to the server run with Vagrant? It may be that the something in that server set up is conflicting with how the webpack-dev-server operates.

I had an issue when trying to use webpack alongside Apache and Wordpress where things in Wordpress were impacting the webpack-dev-server: Wordpress was rewriting URLs and stripping the port required for proxying, and was making all referenced assets absolute URLs rather than starting with a '/' which meant Webpack couldn't reference them.

@joual
Copy link

joual commented Mar 5, 2016

I have the exact same issue. I narrowed it down to the same line. It adds module ID 0 as a parent. I setup an example repo reproducing the issue both with the CLI and a separate server.

https://github.com/joual/hmrbreak

@mummybot
Copy link

mummybot commented Mar 7, 2016

Webpack has many different ways to set up a project, and some of them conflict. The docs aren't too clear on exactly what combination of which you should be using when, and using virtual machines or over networks also complicates issues. I have a working simple repo here with hot module reloading:

https://github.com/mummybot/webpack-hmr-network-multiple-entry-points-issue

@AriaFallah
Copy link

Have you tried

if (module.hot)
  module.hot.accept()

https://webpack.github.io/docs/hot-module-replacement-with-webpack.html#what-is-needed-to-use-it

I know more than a few people who have forgotten this, and didn't know why HMR was not working.

@iroy2000
Copy link
Author

I'm managed to fix the issues I have. Please note that I'm using vagrant, so it might be different for your case.

The following steps are what I changed

  1. I replace my publicPath to be (IS_PRODUCTION ? "/" : "http://localhost:8080/")
  2. I replace the react-hot-loader with react-transform-hmr

Hope it helps :)

@hammeiam
Copy link

@iroy2000 Could you post some more details on step 2 of your resolution? Much appreciated!

@AriaFallah
Copy link

@hammeiam AriaFallah/WebpackTutorial#18 (comment)

@Magomogo
Copy link

Spent hours to this issue before found that stateless functional components of React 0.14 are not supported.

@henrikra
Copy link

I installed this plugin https://github.com/gaearon/react-transform-hmr and now my webpack doesn't do full reload anymore! 👯

@mattisa
Copy link

mattisa commented Sep 12, 2016

@AriaFallah:
if (module.hot)
module.hot.accept()

Works for me. Did not notice that on documentation at first.

@jcrben
Copy link

jcrben commented Jul 2, 2017

fyi, if you're using hotOnly it will use the only-dev-server.js and the error only gets logged out as of webpack 3.0 (see onErrored code).

@orpheus
Copy link

orpheus commented Oct 3, 2019

Have you tried

if (module.hot)
  module.hot.accept()

https://webpack.github.io/docs/hot-module-replacement-with-webpack.html#what-is-needed-to-use-it

I know more than a few people who have forgotten this, and didn't know why HMR was not working.

I'm not immediately certain from the documentation on where exactly to put this code.

@UtmostCreator
Copy link

Have you tried

if (module.hot)
  module.hot.accept()

https://webpack.github.io/docs/hot-module-replacement-with-webpack.html#what-is-needed-to-use-it

I know more than a few people who have forgotten this, and didn't know why HMR was not working.

Please, explain where should we put these 2 lines;

  1. filename;
  2. after which line of code it should go;
  3. some other details (example).

@jakeonfire
Copy link

Please, explain where should we put these 2 lines;

  1. filename;
  2. after which line of code it should go;
  3. some other details (example).

the new location for the relevant documentation is https://webpack.js.org/guides/hot-module-replacement. after reading it, however, i think my issue is that the module in question uses addEventListener, so hot-updating the code would be problematic.

@igorrfc
Copy link

igorrfc commented Aug 3, 2023

For those wondering where to place the recommended snippet:

if (module.hot)
  module.hot.accept()

I tried the entry file configured in my webpack's config (src/index.js in my case) and it worked. Hope it helps anyone else having problems with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests