./node_modules/@angular/core/fesm5/core.js中的Angular警告?

时间:2018-10-03 17:03:39

标签: angular warnings

在部署过程中,我不断收到这些警告:

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

我的项目结构:

enter image description here

我的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'
    })
  })
],

3 个答案:

答案 0 :(得分:1)

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

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

答案 1 :(得分:0)

当我将我的角度应用程序从6更新到7时,出现相同的警告消息。

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

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

答案 2 :(得分:0)

尝试使用添加材料

ng add @angular/material