【问题标题】:Angular 2 + CLI : Error in Maximum call stack size exceededAngular 2 + CLI:超出最大调用堆栈大小错误
【发布时间】:2017-08-06 06:25:58
【问题描述】:

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

版本。

  • @angular/cli: 1.0.0-rc.2
  • 节点:6.9.2
  • 操作系统:win32 x64
  • @angular/common: 2.4.9
  • @angular/编译器:2.4.9
  • @angular/core: 2.4.9
  • @angular/forms: 2.4.9
  • @angular/http:2.4.9
  • @angular/platform-b​​rowser: 2.4.9
  • @angular/platform-b​​rowser-dynamic: 2.4.9
  • @angular/路由器:3.4.9
  • @angular/cli: 1.0.0-rc.2
  • @angular/compiler-cli: 2.4.9

重现步骤。

我运行 ng serv / ng test 或 ng build 并且我有:“超出最大调用堆栈大小错误”

失败给出的日志。

在“ng服务”之后

$ 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 test”也是一样的。

有什么办法解决这个问题吗?

【问题讨论】:

  • 你解决了吗?

标签: angular typescript webpack angular-cli


【解决方案1】:

当我得到一个

超出最大调用堆栈错误

使用以下命令解决:

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

【讨论】:

  • 你能解释一下你为什么这样做以及它是如何解决这个问题的吗?
【解决方案2】:

我遇到了这个问题。我忘记将我的功能路由器模块导入功能模块,所以我收到了上述错误。希望对其他人有所帮助..

【讨论】:

    【解决方案3】:

    如果您的 getter(或方法)返回自身,您将获得循环引用,从而导致超出最大调用堆栈大小异常。 例如。

    public get test(): any {
        return test;
    

    }

    为此检查您的代码。

    【讨论】:

      【解决方案4】:

      在我的例子中,当尝试调用它自己的组件的选择器时会发生这种情况(循环依赖的种类)。

      【讨论】:

        【解决方案5】:

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

        ng serve --aot
        

        如果发现任何错误且可以理解的错误,它将退出构建。

        【讨论】:

        • 对我来说,这导致了同样的错误信息。
        【解决方案6】:

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

        这个错误的原因是你有循环模块依赖问题。

        例如:

        'A' 模块导入(依赖于)'B' 模块

        “B”模块导入(依赖于)“A”模块

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

        如果您有不必要的导入删除不必要的导入

        【讨论】:

        • 欢迎来到 SO。请阅读此how-to-answer 并遵循指南。
        • 如果我必须使用共享组件、管道或指令,我可以构建一个通用模块,如果我想加载包含路由的模块怎么办?看看下面的问题。 stackoverflow.com/questions/43907450/…
        猜你喜欢
        • 2017-10-14
        • 2017-02-27
        • 2021-08-15
        • 1970-01-01
        • 2019-05-14
        • 2019-02-07
        • 1970-01-01
        • 2018-01-24
        • 2011-08-31
        相关资源
        最近更新 更多