关于 Cannot read property 'pop' of undefined 问题的解决方法

#问题:

error  in global.d73a0aee.chunk.css

Cannot read property 'pop' of undefined

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build: `umi build --max_old_space_size=10240`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-06-16T02_21_24_074Z-debug.log

#原因:

因为在我们的新分块配置下,插件似乎无法解决webpack产生的边缘情况。最小的可重现演示是先导入CSS pages/_app.js,然后再使用import()(或next/dynamic)导入组件。

#解决方法:

config.optimization.splitChunks.cacheGroups.[name].enforce = true; name 是指对应打包的名字;
比如:

global: {
    chunks: 'all',
    name: 'global',
    minChunks: 4,
    priority: -22,
    reuseExistingChunk: true,
    enforce: true
},

#具体借鉴:

https://github.com/webpack-contrib/mini-css-extract-plugin/issues/257

https://github.com/vercel/next.js/issues/10161

暂无评论