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

前端 未结 6 993
迷失自我
迷失自我 2020-12-24 10:42

Has anyone faced below warning in \"ng serve\"?

WARNING in ./node_modules/@angular/compiler/src/util.js 10:24-31 Critical dependency: require functi

相关标签:
6条回答
  • 2020-12-24 10:51

    This warning gets thrown if you are importing from src path

    Change the components import statement from

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

    to

    import {  ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
    
    
    
    0 讨论(0)
  • 2020-12-24 10:56

    I had this error (shown in the title) and several others because I tried to implement a 3rd party library.

    So in short, if you get these errors try looking at your 3rd party libraries. In my case it was a barcode scanning library from Scanbot.io.

    0 讨论(0)
  • 2020-12-24 11:05

    It happened to me from this import:

    import { Message } from '@angular/compiler/src/i18n/i18n_ast';
    

    I have a Message interface but autofill import feature defaulted to the one above.

    0 讨论(0)
  • 2020-12-24 11:08

    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.

    0 讨论(0)
  • 2020-12-24 11:08

    Search your app for imports.

    There is a high chance that you imported something similar to from '@angular/compiler/foo' by mistake.

    0 讨论(0)
  • 2020-12-24 11:10

    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.

    0 讨论(0)
提交回复
热议问题