关键依赖项:require函数以无法静态提取依赖项的方式使用 [英] Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

查看:241
本文介绍了关键依赖项:require函数以无法静态提取依赖项的方式使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人在"ng服务"中面临以下警告吗?

Has anyone faced below warning in "ng serve"?

./node_modules/@angular/compiler/src/util.js中的警告 10:24-31关键依赖项:require函数的使用方式不能静态提取依赖项 「wdm」:带有警告.

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 CLI:6.0.8 节点:8.11.3 操作系统:darwin x64 角度:6.0.9 ...动画,通用,编译器,compiler-cli,核心,形式 ... http,语言服务,平台浏览器 ...平台浏览器动态,路由器,升级

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

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

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);
    }
}

推荐答案

我收到此错误,发现了这一点: https://fluin.io/blog/critical-dependency-cannot-be -静态提取,作者表示他也收到了同样的警告.但是,我没有使用Angular Elements,但我知道它可能与相同的问题有关,因此我继续检查我是否在所有导入文件中都使用了@angular/compiler/src/core.

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';

希望对您有帮助.

这篇关于关键依赖项:require函数以无法静态提取依赖项的方式使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆