-
-
Notifications
You must be signed in to change notification settings - Fork 385
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
"Cannot read property 'pop' of undefined" with a common cache group #257
Comments
@OscarBarrett Looks like a bug |
Same problem appeared after update to Babel 7 i don't know if there is a link |
Same problem here even without a cache group. Build fails with:
|
Please create minimum reproducible test repo |
https://github.com/OscarBarrett/mini-css-issue-257
Note that the build succeeds if the |
Ran into this today too.
Little more insight into what may be happening:
I was able to fix this by locally editing mini-css-extract-plugin/src/index.js Line 397 in dd141f2
So it looks like the fallback logic mini-css-extract-plugin/src/index.js Lines 480 to 485 in dd141f2
still works. |
@ndisidore feel free to send a PR 👍 |
Due to webpack-contrib/mini-css-extract-plugin#257, [email protected] should be avoided. I expect next version to fix 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 |
When will this get resolved? I'm running into the same issue here. |
@aganglada When somebody send a PR |
@OscarBarrett Found problem. Maybe related to other people.
You grouped modules to |
Best avoid using an entrypoint as name for a cacheGroup. You can rewrite this config to this: entry: {
first: ['./common.css', './first.jsx'],
second: ['./common.css', './second.jsx'],
},
optimization: {
splitChunks: {
cacheGroups: {
common: {
name: 'common',
chunks: 'initial',
minChunks: 2,
priority: 10,
reuseExistingChunk: true
}
}
}
}, btw. in webpack 5 there will be an error when using an entrypoint name as cacheGroup name. |
Woo, must have missed reading it somewhere in the docs, but
Seems to solve most of the problems I've been having either with this error or emitting to the same chunk. |
Interesting thing. I'm facing this issue only for production mode. My style loaders and cacheGroups are
PS I have no entrypoint names used as keys for cacheGroups |
Moreover , everything works fine when I add |
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 optimization: {
minimize: true,
minimizer: [
new OptimizeCSSAssetsPlugin({})
],
splitChunks: {
cacheGroups: {
mainStyles: {
name: 'main',
test: (m,c,entry = 'main') => m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry,
chunks: 'all',
enforce: true
}
}
}
} The issue I am seeing revolves around this block in the index.js of the plugin. for (const list of modulesByChunkGroup) {
// skip and remove already added modules
while (list.length > 0 && usedModules.has(list[list.length - 1])) list.pop();
// skip empty lists
if (list.length !== 0) {
const module = list[list.length - 1];
const deps = moduleDependencies.get(module);
// determine dependencies that are not yet included
const failedDeps = Array.from(deps).filter(unusedModulesFilter);
// store best match for fallback behavior
if (!bestMatchDeps || bestMatchDeps.length > failedDeps.length) {
bestMatch = list;
bestMatchDeps = failedDeps;
}
if (failedDeps.length === 0) {
// use this module and remove it from list
usedModules.add(list.pop());
success = true;
break;
}
}
} I'm finding that in some cases, all of the arrays in |
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. |
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? |
Setup:
Error:
Rolled back to webpack 3.x. |
@ed-mare double check you webpack version, maybe you have installed global webpack |
I call webpack like so
The interesting thing is that I have two entries where cacheGroup has the same name as the entry. The first one (common) works while the second one (bootstrap) fails with error below:
I don' t understand why it works with one and not the other. It complains about the CSS file (sass) which contains CSS @import directives. Maybe I'm missing a config or special handling for this file? All other CSS (sass) files work. If I change configs to this (entry name and file name are different):
webpack executes without error but it splits the javascript into two files, bootstrap.js and boot.js, and one CSS file bootstrap.css. Okay, promising, I can live with that though I prefer one javascript bundle. When I run this in development mode, javascript executes correctly in the browser. When run in production mode, bootstrap javascript does not execute (like the bootstrap javascript is not present). This page describes the differences between production and development modes FOLLOW UP I figured out the cause of the error. The test should have been more specific,
|
EDIT: in my case the error was caused by my own mistake, fixed here: faceyspacey/extract-css-chunks-webpack-plugin#159 leaving my ravings here in case they are useful...
My splitChunks: {
chunks: 'all',
maxInitialRequests: Infinity,
maxAsyncRequests: Infinity,
maxSize: 200000,
}, I can fix most but not all of the errors by changing it like so: splitChunks: {
// chunks: 'all',
maxInitialRequests: Infinity,
maxAsyncRequests: Infinity,
maxSize: Infinity,
minSize: 0,
}, For me, removing Obviously this is not a good solution because that means my app (with multiple entry points served on the same pages) will have an enormous amount of duplication. |
This is still a problem, and for me renaming the chunks did NOT help (they aren't conflicting with entry points anyway). This is my common: module => ({
name: 'common',
chunks: chunk => chunk.canBeInitial() && !/\.print$|^themes_/.test(chunk.name),
// theme CSS files shouldn't be included in the
// common.css chunk, otherwise they will interfere
// with interface CSS
minChunks: /styles\/themes/.test(module.request) ? 9999 : 2,
}),
|
@evilebottnawi I think the problem here is that pretty much nobody actually knows what exactly the issue is and how to properly fix it! Skipping the whole |
Super ugly workaround to force the non-broken fallback logic without editing the code of this library: class FixedMiniCssExtractPlugin extends MiniCssExtractPlugin {
// This very awful workaround prevents a weird `<undefined>.pop()` in the plugin
// that's caused by who-knows-what (NOT related to dynamic imports).
// See this github issue for details:
// https://github.com/webpack-contrib/mini-css-extract-plugin/issues/257
renderContentAsset(compilation, chunk, modules, requestShortener) {
const [chunkGroup] = chunk.groupsIterable;
let rv;
const getModuleIndex2 = chunkGroup.getModuleIndex2;
try {
chunkGroup.getModuleIndex2 = null;
rv = super.renderContentAsset(compilation, chunk, modules, requestShortener);
} finally {
chunkGroup.getModuleIndex2 = getModuleIndex2;
}
return rv;
}
} |
Webpack is the biggest joke played on the JavaScript community so far. |
As annoying as webpack issues can be, I don't think that comment helps anyone @stephan-v. |
Somebody can create minimum reproducible test repo? Thanks |
This issue is intermittent for me. I am unable to nail down exactly what changes will bring out this bug. I will go weeks without seeing it and then it plagues me for weeks. The workaround also works, but that doesn't play nice with CI testing which I would prefer not to patch the plugin with a hacky workaround. I will continue to try and figure out what brings it out, and get a minimum repro case. |
Failed with version 9.0.5, no problem with version 9.0.7-canary.3. |
I have published a workaround for the version 0.5.0 |
why this issue closed, it is not solved. |
Following up from research by @ndisidore and @cshomo11, I discovered that some chunks in the chunk group had modules that were not in the chunk group's |
Still an issue: Is there any fix? ERROR in chunk layout.theme [initial] |
I don't know why but add |
I'm using For example have a look to |
This issue is still not solved entirely? I ran into this out of nowhere. XD |
Somebody still the problem? If yes can you try #341 (comment), I want to improve error reporting and close this issue. |
Avoid using the entry point as the name for the cacheGroup in webpack@4 |
using "enforce: true" is not an option for me, because it ignores the cacheGroup.minSize property and I need it. Is there another way around this? |
In my case this was resolved by changing the priority of the shared chunk. My chunking configuration is something similar to that used in Next.js
Changing the When checking the output bundles using |
I ran into this after upgrading to 0.4.2.
common.css is set up like so:
And has an explicit entry with the following:
The text was updated successfully, but these errors were encountered: