Angular 12 警告严重依赖 : the request of a dependency is an expression

标签 angular webpack angular12 angular-builder

我在 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/

相关文章:

node.js - 如何在 Angular 和 Node.js 中使用 socket.io?

javascript - 为 .ejs 设置 Webpack

angular - 一个 @ngrx/effect 中的多个 Http 调用

Angular 12 - 双向绑定(bind)给出错误 : The property and event halves of the two-way binding 'prop_name' are not bound to the same target

浏览器中缺少 Angular 12 源映射

angular - bindCallback 仅发出一次

angular - Ionic-3 找不到管道

javascript - 可观察的异步与同步

javascript - webpack动态添加全局常量

javascript - 为什么我的配置无法正确解析别名?