Can';t运行由Webpack 4和SplitChunksPlugin构建的Angular 6
我正在尝试将Angular 6应用程序迁移到使用Webpack 4而不是Webpack 3,但在运行应用程序时出现以下错误:Can';t运行由Webpack 4和SplitChunksPlugin构建的Angular 6,angular,webpack,Angular,Webpack,我正在尝试将Angular 6应用程序迁移到使用Webpack 4而不是Webpack 3,但在运行应用程序时出现以下错误: compiler.js:215 Uncaught Error: Can't resolve all parameters for IntroComponent: (?). 当我使用以下优化时,上述错误不会发生: optimization = { splitChunks: { chunks: 'all' } } 这将生成以下捆绑包: main.js m
compiler.js:215 Uncaught Error: Can't resolve all parameters for IntroComponent: (?).
当我使用以下优化时,上述错误不会发生:
optimization = {
splitChunks: {
chunks: 'all'
}
}
这将生成以下捆绑包:
- main.js
- main.js.map
- polyfills.js
- polyfills.js.map
- vendor.js
- vendor.js.map
- 供应商~main.js
- 供应商~main.js.map
- 供应商~polyfills.js
- 供应商~polyfills.js.map
- vendors~vendor.js
- vendors~vendor.js.map
entry: {
polyfills: helpers.root('/client/src/polyfills.ts'),
vendor: helpers.root('/client/src/vendor.ts'),
main: helpers.root('/client/src/main.ts'),
},
现在,我尝试只生成三个bundle并使应用程序正常工作:
- main.js
- vendor.js
- polyfills.js
optimization = {
splitChunks: {
chunks: 'all',
cacheGroups: {
polyfills: {
name: 'polyfills',
test: /polyfills|core-js|zone/,
chunks: 'all',
priority: 2,
enforce: true
},
vendor: {
name: 'vendor',
test: /node_modules/,
chunks: 'all',
priority: 1,
enforce: true
}
}
},
};
这成功地生成了我想要的三个bundle,但当我运行应用程序时,出现了前面提到的错误:
compiler.js:215 Uncaught Error: Can't resolve all parameters for IntroComponent: (?).
我比较了bundles vendor.js和以前的vendors~main.js,唯一的区别是:
> /***/ "./node_modules/webpack/buildin/global.js":
> /*!***********************************!*\
> !*** (webpack)/buildin/global.js ***!
> \***********************************/
> /*! no static exports found */
> /*! ModuleConcatenation bailout: Module is not an ECMAScript module */
> /***/ (function(module, exports) {
>
> var g;
>
> // This works in non-strict mode
> g = (function() {
> return this;
> })();
>
> try {
> // This works if eval is allowed (see CSP)
> g = g || Function("return this")() || (1, eval)("this");
> } catch (e) {
> // This works if the window reference is available
> if (typeof window === "object") g = window;
> }
>
> // g can still be undefined, but nothing to do about it...
> // We return undefined, instead of nothing here, so it's
> // easier to handle this case. if(!global) { ...}
>
> module.exports = g;
>
>
> /***/ }),
>
其他捆绑包较小,看起来类似。我怎样才能解决这个问题?这次迁移让我很头疼
更新:
我无法通过分为供应商和polyfills来解决问题,但我以以下优化配置结束:
const optimization = {
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendor',
test: /\/node_modules\//,
chunks: 'all',
priority: 0,
enforce: true,
},
},
},
嗨,桑德罗,你解决了这个问题吗?我也在尝试迁移wo webpack 4,它花费了我很多宝贵的时间…是的,我解决了它。我明天发布,好吗?@user5328504,我更新了帖子,但我无法解决我想要的问题。谢谢发布更新。出于好奇,你在用AoT吗?@VinegarStrokes,不,我没有用AoT。