问题描述
有人在ng serve"中遇到过以下警告吗?
Has anyone faced below warning in "ng serve"?
./node_modules/@angular/compiler/src/util.js 中的警告10:24-31 关键依赖:require 函数的使用方式无法静态提取依赖ℹ 「wdm」:编译有警告.
角度版本控制:
Angular CLI:6.0.8节点:8.11.3操作系统:达尔文 x64角度:6.0.9... 动画、通用、编译器、编译器-cli、核心、表单... http、语言服务、平台浏览器... 平台浏览器动态,路由器,升级
我尝试更新 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-statically-extracted,作者表明他收到了同样的警告.但是,我没有使用 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函数的使用方式无法静态提取依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!