Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

Has anyone faced below warning in "ng serve"?

WARNING in ./node_modules/@angular/compiler/src/util.js 10:24-31 Critical dependency: require function is used in a way in which dependencies cannot be statically extracted ℹ 「wdm」: Compiled with warnings.

Angular versioning:

Angular CLI: 6.0.8 Node: 8.11.3 OS: darwin x64 Angular: 6.0.9 ... animations, common, compiler, compiler-cli, core, forms ... http, language-service, platform-browser ... platform-browser-dynamic, router, upgrade

I tried updating CLI and Angular but no success. Code inside util.js looks like:

function (factory) {      if (typeof module === "object" && typeof module.exports === "object") {          var v = factory(require, exports);          if (v !== undefined) module.exports = v;      }      else if (typeof define === "function" && define.amd) {          define("@angular/compiler/src/util", ["require", "exports"], factory);      }  }
like image 858
Aman Avatar asked Jul 13 '18 06:07

Aman


2 Answers

I got this error and found this: https://fluin.io/blog/critical-dependency-cannot-be-statically-extracted, where the author shows he was getting the same warning. However, I wasn't using Angular Elements, but I got the idea it might be related to the same problem, so I went ahead and checked whether I was using @angular/compiler/src/core in any of my imports.

And I was indeed doing so. The fix was as simple as removing the import line, which in my case was:

import { ViewEncapsulation } from '@angular/compiler/src/core'; 

And then the editor autoimported it as follows:

import { Component, OnInit, ViewEncapsulation } from '@angular/core'; 

I hope it helps.

like image 194
Jorge Solis Avatar answered Oct 12 '22 15:10

Jorge Solis


I experienced same error, when I've imported by mistake EventEmitter from protractor instead of @angular/core.

Changing import { EventEmitter } from 'protractor'; to import { EventEmitter } from '@angular/core'; fixed it.

like image 45
mimo Avatar answered Oct 12 '22 14:10

mimo