首页 文章

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

提问于
浏览
10

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

警告在./node_modules/@angular/compiler/src/util.js 10:24-31严重依赖:要求函数以不能静态提取依赖关系的方式使用ℹ“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);
    }
}

1 回答

  • 15

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

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

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

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

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

    我希望它有所帮助 .

相关问题