mini-css-extract-plugin: "Cannot read property 'pop' of undefined" with a common cache group
I ran into this after upgrading to 0.4.2.
ERROR in chunk common [initial]
common.css
Cannot read property 'pop' of undefined
TypeError: Cannot read property 'pop' of undefined
at MiniCssExtractPlugin.renderContentAsset (.../node_modules/mini-css-extract-plugin/dist/index.js:343:44)
at Object.render (.../node_modules/mini-css-extract-plugin/dist/index.js:175:32)
at Compilation.createChunkAssets (.../node_modules/webpack/lib/Compilation.js:2358:29)
at hooks.optimizeTree.callAsync.err (.../node_modules/webpack/lib/Compilation.js:1268:10)
at AsyncSeriesHook.eval [as callAsync] (eval at create (.../node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook [as _callAsync] (.../node_modules/tapable/lib/Hook.js:35:21)
at Compilation.seal (.../node_modules/webpack/lib/Compilation.js:1213:27)
at hooks.make.callAsync.err (.../node_modules/webpack/lib/Compiler.js:547:17)
at _done (eval at create (.../node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:9:1)
at _err16 (eval at create (.../node_modules/tapable/lib/HookCodeFactory.js:24:12), <anonymous>:218:22)
at _addModuleChain (.../node_modules/webpack/lib/Compilation.js:1064:12)
at processModuleDependencies.err (.../node_modules/webpack/lib/Compilation.js:980:9)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)
common.css is set up like so:
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'initial',
minChunks: 3,
priority: 10,
reuseExistingChunk: true
}
}
}
},
And has an explicit entry with the following:
common: [
path.resolve(srcPath, 'vendor.scss'),
path.resolve(srcPath, 'main.scss')
]
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 27
- Comments: 41 (10 by maintainers)
Commits related to this issue
- build(demo,lib): Update deps, use webpack4 Due to webpack-contrib/mini-css-extract-plugin#257, mini-css-extract-plugin@0.4.2 should be avoided. I expect next version to fix this issue. — committed to GerkinDev/ngx-showdown by deleted user 6 years ago
- fix: Fix renderContentAsset based on Github Issue suggestion https://github.com/webpack-contrib/mini-css-extract-plugin/issues/257 — committed to boostmyschool/mini-css-extract-plugin by golmansax 5 years ago
- fix(order): find modules from each chunk in group fixes #257 — committed to ryansully/mini-css-extract-plugin by ryansully 5 years ago
- fix: Fix renderContentAsset based on Github Issue suggestion https://github.com/webpack-contrib/mini-css-extract-plugin/issues/257 — committed to boostmyschool/mini-css-extract-plugin by golmansax 5 years ago
- fix: Cannot read property 'pop' of undefined https://github.com/webpack-contrib/mini-css-extract-plugin/issues/257 [UTCORE-121] — committed to softwaregroup-bg/ut-webpack by deleted user 3 years ago
Webpack is the biggest joke played on the JavaScript community so far.
Best avoid using an entrypoint as name for a cacheGroup. You can rewrite this config to this:
btw. in webpack 5 there will be an error when using an entrypoint name as cacheGroup name.
@aganglada When somebody send a PR
When will this get resolved? I’m running into the same issue here.
Moreover , everything works fine when I add
{ enforce: true }
in my splitChunks entries or remove{ chunks: 'all' }
from themRan into this today too.
Little more insight into what may be happening:

bestMatch
never gets a value becausesortedModules
is empty (note that in my case, the function input parammodules
inrenderContentAsset
has 3 items in it). This is becausegetModuleIndex2
returnsundefined
for every module that gets passed in (I verified this manually by running all the modules through it).I was able to fix this by locally editing
index.js
and changing this if statement to always return false https://github.com/webpack-contrib/mini-css-extract-plugin/blob/dd141f2aacddbb30d9129a14425085b11f3cba8d/src/index.js#L397So it looks like the fallback logic https://github.com/webpack-contrib/mini-css-extract-plugin/blob/dd141f2aacddbb30d9129a14425085b11f3cba8d/src/index.js#L480-L485 still works.
@OscarBarrett Found problem. Maybe related to other people.
You grouped modules to
common
chunk and usecommon: './common.css'
entry. Just change namecommon
entry tocommonStyle
why this issue closed, it is not solved.
hi @sokra , I also encountered the same problem. extract-text-webpack-plugin is all OK but only using [hash]… , and mini-css-extract-plugin throws the error: Cannot read property ‘pop’ of undefined . there are lots of scenarios using an entrypoint name as cacheGroup name, Why not support it and fix what @cshomo11 posted but remove it in webpack5? Looking forward to your reply, thanks.
Ran into this issue myself and going off of what @ndisidore posted I think I see another issue at play, at least with my setup.
webpack.config.js
The issue I am seeing revolves around this block in the index.js of the plugin.
I’m finding that in some cases, all of the arrays in
modulesByChunkGroup
are empty. When this happens,bestMatch
is never set andsuccess=true
is also never reached so the.pop
error occurs. I’ve tried to do some empty array checks but that doesn’t seem to be the right way to tackle this issue. Hoping this will help track down the right fix for this issue.I can totally help with a PR. May need a little direction on the correct way to do it vs the quick fix.
It looks like
getModuleIndex2
is just a.get
on the map of the chunkGroup. So essentially what we’re trying to do is see if the current module is in the given chunk group. Under what circumstances would this never be the case and are those expected?Some more context around those specifics.
I don’t know why but add
enforce: true
does fix this for my vendors cache group.Failed with version 9.0.5, no problem with version 9.0.7-canary.3.
As annoying as webpack issues can be, I don’t think that comment helps anyone @stephan-v.
Super ugly workaround to force the non-broken fallback logic without editing the code of this library:
Setup:
Error:
Rolled back to webpack 3.x.
What if I want to combine css content from entry and also splitChunks cachegroup? If we change entry to commonStyle, basically, it will create common.css and commonStyle.css. Instead, I want these two file contents to be merged to one file (common.css). How can we achieve that?