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

Get an error if HMR and hot together #2146

Closed
a-dev opened this issue Jun 23, 2019 · 12 comments
Closed

Get an error if HMR and hot together #2146

a-dev opened this issue Jun 23, 2019 · 12 comments

Comments

@a-dev
Copy link

a-dev commented Jun 23, 2019

I had an trouble in a project that hotModuleReplacement didn't work, got an error 'Maximum call stack size exceeded'.
It's an old issue that flag --hot and hotModuleReplacement can't be together.

I removed HotModuleReplacementPlugin() form config:

if (devServer.hmr) {
  this.plugins.append('HotModuleReplacement', new webpack.HotModuleReplacementPlugin()) // remove this line and HMR will work
  this.config.output.filename = '[name]-[hash].js'
}

I use last versions:
"webpack": "^4.35.0",
"webpack-dev-server": "^3.7.2",

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Jun 26, 2019

image

Does it work if you omit ‘—hot’? It should work if you just set devServer.hot: true.

@babel92
Copy link

babel92 commented Jun 27, 2019

Ran into similar issue after upgrading from 4.0.2 to 4.0.3. webpack-dev-server actually checks for this plugin but somehow it failed (https://github.com/webpack/webpack-dev-server/blob/802aa30cc0a549803e64b74a7085a2c549c71f41/lib/utils/updateCompiler.js#L18)

@a-dev
Copy link
Author

a-dev commented Jun 27, 2019

Does it work if you omit ‘—hot’? It should work if you just set devServer.hot: true.

@jakeNiemiec If you set hmr: true you already have a ‘--hot’, cause hot: devServer.hmr,
see here https://github.com/rails/webpacker/blob/master/package/environments/development.js

@jakeNiemiec
Copy link
Member

What issue are you having? We can only fix problems with rails/webpacker here.

@a-dev
Copy link
Author

a-dev commented Jun 27, 2019

I just sad that you have the flag hot: true and append HotModuleReplacement if hmr: true in yml config. But it can make error, cause it isn’t necessary to append HotModuleReplacement if —hot option omitted.

@jakeNiemiec
Copy link
Member

jakeNiemiec commented Jun 27, 2019

it can make error, cause it isn’t necessary to append HotModuleReplacement if —hot option omitted

I would think that the solution is: just don't append the HotModuleReplacement plugin. I also would not use both the --hot flag with webpacker.

Does removing the HotModuleReplacementPlugin() from your config fix things?

@a-dev
Copy link
Author

a-dev commented Jun 27, 2019

@jakeNiemiec I don’t have HotModuleReplacementPlugin() in my config, it’s in the config of Webpacker. And I showed in this issue (first post) if you remove appending of HotModuleReplacementPlugin() you fix this error.
In Webpacker config it’s here — https://github.com/rails/webpacker/blob/master/package/environments/development.js#L11

@jakeNiemiec
Copy link
Member

Apologies, the link from @babel92 completely threw me off. How are you invoking webpack with --hot? (I assume something like ./bin/webpack-dev-server --hot)

@babel92
Copy link

babel92 commented Jun 27, 2019

Actually I think @a-dev and I are having the same issue - if you set hmr: true in webpacker.yml, webpacker inserts HotModuleReplacementPlugin and uses hot: true to launch webpack-dev-server (which should be equivalent to --hot option). And webpack-dev-server would try to check for this plugin before inserting it again but it failed to identify it somehow in our cases. My suggestion was just don't append this plugin in @rails/webpacker as a-dev already proposed, given webpack-dev-server will do that anyway.

@justin808
Copy link
Contributor

I submitted a PR to fix this: #2439.

@rails rails deleted a comment May 4, 2020
@rails rails deleted a comment May 4, 2020
@justin808
Copy link
Contributor

@gauravtiwari can you reopen: #2439

I think given the docs clearly state that this is correct, we should consider #2439.

@justin808
Copy link
Contributor

@guillaumebriday Let's close and let somebody reopen if an issue with v6.

@dhh dhh closed this as completed Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants