我在 ng build (Angular 12) 后收到这些警告:
./node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:35289:13-34 - 警告:关键依赖项:依赖项的请求是一个表达式
./node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:35301:13-100 - 警告:关键依赖项:依赖项的请求是一个表达式
我正在使用 @angular-builders/custom-webpack 从初始包中提取 moment.js。
如果我禁用了 @angular-builders/custom-webpack,那么一切都会顺利,警告也会消失。
此外,如果我在 custom-webpack.config.js 中添加以下内容,警告就会消失:
new webpack.ContextReplacementPlugin(
/\@angular(\\|\/)core(\\|\/)__ivy_ngcc__(\\|\/)fesm2015/,
path.join(__dirname, './src'),
{}
),
请问到底是什么导致了这些警告?有没有其他解决方案可以处理它,而无需像上面那样将插件添加到 webpack 配置中?谢谢。
最佳答案
我从 Angular 开发团队得到了以下反馈:
This comes from code in the deprecated SystemJsNgModuleLoader and is normally suppressed when using the CLI builders, which also uses ContextReplacementPlugin. I don't think there is an alternative to suppress them, other than to not suppress them and ignore the warnings.
https://github.com/angular/angular/issues/43092#issuecomment-895848535
因此,我最终在 custom-webpack.config.js 中使用了上述 CLI 构建器代码,如下所示:
// Always replace the context for the System.import in angular/core to prevent warnings.
new ContextReplacementPlugin(
/\@angular(\\|\/)core(\\|\/)/,
path.join(__dirname, '$_lazy_route_resources'),
{}
),
关于Angular 12 警告严重依赖 : the request of a dependency is an expression,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68698503/