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

CommonsChunkPlugin can break chunks when extracting entry modules #4795

Closed
jbellenger opened this issue Apr 28, 2017 · 5 comments · Fixed by #4815
Closed

CommonsChunkPlugin can break chunks when extracting entry modules #4795

jbellenger opened this issue Apr 28, 2017 · 5 comments · Fixed by #4815

Comments

@jbellenger
Copy link
Contributor

jbellenger commented Apr 28, 2017

Do you want to request a feature or report a bug?
bug

What is the current behavior?
CommonsChunkPlugin can extract a chunks entryModule in a way that breaks the chunk.
Example: In this gist, chunk pageA.b287e3.js has entry module ./entry.js, which is neither contained within the chunk nor automatically loaded by the webpack runtime.
Trying to load chunk pageA.b287e3.js tenders this uncaught error:

Uncaught TypeError: Cannot read property 'call' of undefined
    at __webpack_require__ (manifest.cc96ba.js:55)
    at webpackJsonpCallback (manifest.cc96ba.js:26)
    at pageA.b287e3.js:1

If the current behavior is a bug, please provide the steps to reproduce.
Repro repo at https://github.com/jbellenger/CommonsChunkPlugin-async-testcase
Gist of build results at https://gist.github.com/jbellenger/f16429c8787969591e245d024c75db69

What is the expected behavior?
CommonsChunkPlugin should not modify chunks in ways that prevents them from loading. Either of these might fix the issue:

  • a chunks entryModule should never be extracted
  • an async chunk should be loaded by the runtime before the modified chunk is executed

Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.
This is observed in webpack@2.4.1, node 6.9.5, on osx 10.11.6.
I originally reported this as globalize-webpack-plugin issue 44. After seeing different behavior using webpack@1, I suspect this is an issue with CommonsChunkPlugin in webpack@2

@TheLarkInn
Copy link
Member

@jbellenger Thank you so much for this report. 🙇

@sokra
Copy link
Member

sokra commented May 4, 2017

The globalize-webpack-plugin looks really hacky...

Anyway this was caused by a webpack bug. #4815 fixes the bug.

@Alex-Sokolov
Copy link

But how to extract common dependencies from async chunks now?

@jbellenger
Copy link
Contributor Author

jbellenger commented May 19, 2017

@Alex-Sokolov see #4850 . You can work around this bug and #4850 by downgrading to webpack-2.4.1 and changing minChunks in your webpack config to:

minChunks: (module, count) => {
  if (module.depth === 0) {
    return false;
  }
  return count >= 42;  // change value as needed 
}

@Alex-Sokolov
Copy link

@jbellenger Thanks for answer! Already downgraded to 2.4.1 where all works, but I think maybe there is a new way to do this in 2.5.1 :)

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

Successfully merging a pull request may close this issue.

4 participants