关键依赖关系:require函数的使用方式是无法静态提取依赖关系

Ama*_*man 43 typescript angular angular6

"ng serve"中是否有人面临以下警告?

警告在./node_modules/@angular/compiler/src/util.js 10:24-31严重依赖:require函数的使用方式是无法静态提取依赖关系ℹ"wdm":编译时带有警告.

角度版本:

Angular CLI:6.0.8节点:8.11.3操作系统:darwin x64 Angular:6.0.9 ...动画,通用,编译器,编译器 - cli,核心,表单... http,语言服务,平台浏览器..平台浏览器动态,路由器,升级

我尝试更新CLI和Angular但没有成功.util.js中的代码如下所示:

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

小智 102

我收到了这个错误并发现了这个:https: //fluin.io/blog/critical-dependency-cannot-be-statically-extracted,作者显示他收到了相同的警告.但是,我没有使用Angular Elements,但我知道它可能与同一个问题有关,所以我继续检查我是否在我的@angular/compiler/src/core任何导入中使用.

而我确实这样做了.修复就像删除导入行一样简单,在我的例子中是:

import { ViewEncapsulation } from '@angular/compiler/src/core';
Run Code Online (Sandbox Code Playgroud)

然后编辑器自动导入如下:

import { Component, OnInit, ViewEncapsulation } from '@angular/core';
Run Code Online (Sandbox Code Playgroud)

我希望它有所帮助.

  • 谢谢!这是我一直在寻找的解决方案。 (3认同)
  • 也谢谢你。不仅仅是这个模块,检查你的导入是否有恶意导入。 (2认同)
  • 就我而言,在Angular 7上,Visual Studio Code从@ angular / compiler / src / core自动完成了导入ViewEncapsulation的操作,并给出了此错误。这样解决了,谢谢 (2认同)

mim*_*imo 21

我遇到了同样的错误,当我错误地EventEmitter从而protractor不是@angular/core.

更改import { EventEmitter } from 'protractor';import { EventEmitter } from '@angular/core';修复它。


Yur*_*uri 5

搜索您的应用程序以进行导入。

您很有可能from '@angular/compiler/foo'错误地导入了类似的内容。


小智 5

如果您从 src 路径导入,则会抛出此警告

将组件导入语句从

import { ChangeDetectionStrategy, ViewEncapsulation } from '@angular/compiler/src/core';
Run Code Online (Sandbox Code Playgroud)

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


Run Code Online (Sandbox Code Playgroud)


小智 5

我发现了一个类似的问题:

./node_modules/@angular/compiler/src/util.js:10:24-31 - 警告:关键依赖项:require 函数的使用方式无法静态提取依赖项

我记得使用stringify而不是JSON.stringify并且自动导入(使用 vs code)为:

import { stringify } from '@angular/compiler/src/util';
Run Code Online (Sandbox Code Playgroud)

我删除了此自动导入并将代码更正为 JSON.stringify。