【问题标题】:Angular WARNING in ./node_modules/@angular/core/fesm5/core.js?./node_modules/@angular/core/fesm5/core.js 中的角度警告?
【发布时间】:2018-10-03 17:03:38
【问题描述】:

我在部署时不断收到这些警告:

WARNING in ./node_modules/@angular/core/fesm5/core.js
4996:15-36 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/@angular/core/fesm5/core.js
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/main.ts

WARNING in ./node_modules/@angular/core/fesm5/core.js
5008:15-102 Critical dependency: the request of a dependency is an expression
 @ ./node_modules/@angular/core/fesm5/core.js
 @ ./src/app/app.module.ts
 @ ./src/main.ts
 @ multi (webpack)-dev-server/client?http://localhost:8080 ./src/main.ts

我尝试过的:

https://github.com/angular/angular/issues/20357

我的项目结构:

我的 webpack.config.js:

var path = require('path');
plugins: [
  new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)esm5/, path.join(__dirname, './src')),
  new HtmlWebpackPlugin({
    template: './src/index.html',
    filename: 'index.html',
    inject: 'body'
  }),
  new webpack.DefinePlugin({
    // global app config object
    config: JSON.stringify({
      apiUrl: 'http://localhost:4000'
    })
  })
],

【问题讨论】:

  • 您是否尝试在上面发布的webpack.config.js 中将[...]esm5/ 更改为[...]fesm5/
  • 这行得通,如果您将此作为答案发布,我会接受。你能解释一下为什么这行得通而前者不行吗?
  • 误会了,我在angular 7中遇到这个,webpack不再直接配置了。想说遇到这个,但是没办法配置。但是作为旁注,ng 8 中支持的方式是使用 ngx-build-plus npm 模块来覆盖/扩展基本 webpack 配置。

标签: angular warnings


【解决方案1】:

您的方向是正确的,除了插件名称,请尝试在现有的 ContextReplacementPlugin 之后将以下内容添加到您的 webpack.config.js 中

new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/, path.join(__dirname, './src')),

【讨论】:

  • @FlavorScape 这很不幸,但是,最初的问题是关于 webpack 以及我的回答
【解决方案2】:

当我将我的 Angular 应用程序从 6 更新到 7 时,同样的警告消息。

我通过在 tsconfig.json 的 compilerOptions 中添加路径 "@angular/<em>": ["../node_modules/@angular/</em>"] 来删除消息,

但我不确定这是最好的解决方案。

【讨论】:

  • 你能告诉我们你的意思是这样的例子吗? :真,“声明”:假,“模块”:“es2015”,“moduleResolution”:“节点”,“emitDecoratorMetadata”:真,“@angular/”:[“../node_modules/@angular/”]“实验装饰器”:真,“目标”:“es5”,“typeRoots”:[“node_modules/@types”],“lib”:[“es2017”,“dom”]}
  • 那样 --> "compilerOptions": { "outDir": "./dist/out-tsc", ... "paths": { "@app/*": ["app /*"], "@env/*": ["environments/*"], ... "@angular/*": ["../node_modules/@angular/*"] } }
【解决方案3】:

尝试使用添加材质

ng add @angular/material

【讨论】:

    猜你喜欢
    • 2018-07-21
    • 2019-10-15
    • 2018-08-30
    • 2019-01-30
    • 2018-08-03
    • 1970-01-01
    • 1970-01-01
    • 2018-07-27
    • 2020-03-04
    相关资源
    最近更新 更多