angular - Angular 12 警告严重依赖:依赖的请求是一个表达式
问题描述
我在 ng build (Angular 12) 之后收到这些警告:
./node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:35289:13-34 - Warning: Critical dependency: the request of a dependency is an expression
./node_modules/@angular/core/__ivy_ngcc__/fesm2015/core.js:35301:13-100 - Warning: Critical dependency: the request of a dependency is an expression
我正在使用 @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 开发团队得到以下反馈:
这来自已弃用的SystemJsNgModuleLoader中的代码,并且在使用 CLI builders时通常会被抑制,它也使用 ContextReplacementPlugin。我认为除了不压制它们并忽略警告之外,没有其他方法可以压制它们。
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'),
{}
),
推荐阅读
- python - 声明似乎没有效果十六进制到十进制转换器
- javascript - 异步调用nodejs和python
- google-maps - 确定用于旅行的车辆类型
- java - 如何选择文件的路径而不是上传文件?
- c++ - llvm::BasicBlock::isLandingPad 未按预期运行
- javascript - HTML 输入复选框总是返回 false
- python - 获取 8 个字符的 UUID
- python - AttributeError:模块“sst”没有属性“train_reader”
- javascript - 在组件中使用渲染道具时,有哪些常见的陷阱可以避免无限重新渲染?
- r - ggplot2 不会将图例添加到具有多个层的箱线图