Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular WARNING in ./node_modules/@angular/core/fesm5/core.js?

Tags:

I keep getting these Warnings while deploying:

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

What I've tried:

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

My project structure:

enter image description here

My 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'
    })
  })
],
like image 471
Muhammad Ali Avatar asked Oct 03 '18 17:10

Muhammad Ali


2 Answers

You were on the right direction, except the pluging name, try to add the following to your webpack.config.js after the existing ContextReplacementPlugin

new webpack.ContextReplacementPlugin(/\@angular(\\|\/)core(\\|\/)fesm5/, path.join(__dirname, './src')),
like image 106
Serg.ID Avatar answered Oct 11 '22 12:10

Serg.ID


Same warning message when i update my angular app from 6 to 7.

I remove the message by adding the path "@angular/": ["../node_modules/@angular/"] in compilerOptions in the tsconfig.json,

But I'm not sure this is the best solution.

like image 28
Dioux Avatar answered Oct 11 '22 12:10

Dioux