角度 2 + CLI :超出最大调用堆栈大小时出错



我的 Ng2 项目有 3 - 4 天的问题。

版本。

  • @angular/命令行界面:1.0.0-rc.2
  • 节点:6.9.2
  • 操作系统: Win32 x64
  • @angular/通用:2.4.9
  • @angular/编译器:2.4.9
  • @angular/核心:2.4.9
  • @angular/表单:2.4.9
  • @angular/http: 2.4.9
  • @angular/平台浏览器:2.4.9
  • @angular/平台浏览器动态:2.4.9
  • @angular/路由器:3.4.9
  • @angular/命令行界面:1.0.0-rc.2
  • @angular/编译器-cli:2.4.9

重现步骤。

我运行 ng serv/ng 测试或 ng 构建,我有:"超出最大调用堆栈大小的错误">

失败给出的日志。

在"ng serve"之后

$ ng serve
** NG Live Development Server is running on http://localhost:4200 **
Hash: a73c4ecdb8222366629e
Time: 16536ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 405 kB {5} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 41.1 kB {4} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 149 kB {5} [initial] [rendered]
chunk    {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 244 kB {5} [initial] [rendered]
chunk    {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.75 MB [initial] [rendered]
chunk    {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
ERROR in Maximum call stack size exceeded
webpack: Failed to compile.

在我保存了一次之后,一切都很好:

$ ng serve
** NG Live Development Server is running on http://localhost:4200 **
Hash: a73c4ecdb8222366629e
Time: 16536ms
chunk    {0} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 405 kB {5} [initial] [rendered]
chunk    {1} main.bundle.js, main.bundle.js.map (main) 41.1 kB {4} [initial] [rendered]
chunk    {2} styles.bundle.js, styles.bundle.js.map (styles) 149 kB {5} [initial] [rendered]
chunk    {3} scripts.bundle.js, scripts.bundle.js.map (scripts) 244 kB {5} [initial] [rendered]
chunk    {4} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.75 MB [initial] [rendered]
chunk    {5} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
ERROR in Maximum call stack size exceeded
webpack: Failed to compile.
webpack: Compiling...
Hash: 02fd7618c3e2de3db52e
Time: 9915ms
chunk    {0} 0.chunk.js, 0.chunk.js.map 926 kB {1} {2} {3} {5} [rendered]
chunk    {1} 1.chunk.js, 1.chunk.js.map 397 kB {0} {2} {3} {5} [rendered]
chunk    {2} 2.chunk.js, 2.chunk.js.map 33.1 kB {0} {1} {3} {5} [rendered]
chunk    {3} 3.chunk.js, 3.chunk.js.map 2.96 kB {0} {1} {2} {5} [rendered]
chunk    {4} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 405 kB {9} [initial] [rendered]
chunk    {5} main.bundle.js, main.bundle.js.map (main) 41.1 kB {8} [initial] [rendered]
chunk    {6} styles.bundle.js, styles.bundle.js.map (styles) 149 kB {9} [initial] [rendered]
chunk    {7} scripts.bundle.js, scripts.bundle.js.map (scripts) 244 kB {9} [initial] [rendered]
chunk    {8} vendor.bundle.js, vendor.bundle.js.map (vendor) 2.75 MB [initial] [rendered]
chunk    {9} inline.bundle.js, inline.bundle.js.map (inline) 0 bytes [entry] [rendered]
webpack: Compiled successfully.

对于"ng测试"是一样的。

有什么想法可以解决这个问题吗?

我遇到了同样的错误。通过删除不必要的导入来解决

此错误的原因您有循环模块依赖问题

例如:

"A"模块

导入(取决于("B"模块

"B"模块

导入(从属到("A"模块

我建议你构建一个公共模块,其他模块应该导入公共模块。

如果您有不必要的导入

,请删除不必要的导入

我发现调试这个的最佳方法是:

ng serve --aot

如果发现任何错误并出现可理解的错误,它将退出建筑物。

如果你 getter(或方法(返回自身,你将得到循环引用,导致最大调用堆栈大小超出异常。前任。

public get test(): any {
    return test;

}

为此查看您的代码。

就我而言,当尝试调用其自己的组件的选择器(循环依赖关系(时会发生这种情况。

我遇到了这个问题。我忘了将功能路由器模块导入功能模块,因此出现上述错误。希望它能帮助别人。

删除node_modules文件夹,然后运行npm install并再次ng serve为我做了这个技巧。

从这里得到提示:https://github.com/angular/angular-cli/issues/17106

就我而言,我将一个组件放在错误的子模块中。 对于一个放错地方的组件来说,这是一个神秘的错误。 例如:

src
|-account
    |-account.modue.ts
|-admin
    |-admin.module.ts
    |-users
        |-user-maintenance.component.ts

account.module.ts
   ...
   @NgModule({
       declarations: [
           UserMaintenanceComponent   // this should be in admin.module.ts
   ...

由于模块导入的循环依赖性,我得到了此错误。

A -> B,

B -> A,

我只是通过从 B 中删除 A 并添加到 app.module.ts 来解决这个问题。

当我得到一个

超出最大调用堆栈中的错误

使用以下命令解决:

ng build --prod --base-href "PATH OF SERVER" --aot=false --build-optimizer=false

最新更新