angular-cli: Maximum call stack size exceeded after updating `@angular/compiler-cli`

๐Ÿž Bug report

Command (mark with an x)

  • new
  • build
  • serve
  • test
  • e2e
  • generate
  • add
  • update
  • lint
  • xi18n
  • run
  • config
  • help
  • version
  • doc

Is this a regression?

Yes, the previous version in which this bug was not present was: 9.0.2

Description

After updating `@angular/compiler-cli 9.0.3` during ng serve I receive following error: `ERROR in Maximum call stack size exceeded`

๐Ÿ”ฌ Minimal Reproduction

๐Ÿ”ฅ Exception or Error

ERROR in Maximum call stack size exceeded

๐ŸŒ Your Environment

ng version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / โ–ณ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.0.3
Node: 12.13.1
OS: linux x64

Angular: 9.0.3
... animations, cli, common, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.3
@angular-devkit/build-angular     0.900.3
@angular-devkit/build-optimizer   0.900.3
@angular-devkit/build-webpack     0.900.3
@angular-devkit/core              9.0.3
@angular-devkit/schematics        9.0.3
@angular/cdk                      9.1.0
@angular/compiler                 9.0.2
@angular/material                 9.1.0
@ngtools/webpack                  9.0.3
@schematics/angular               9.0.3
@schematics/update                0.900.3
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

Anything else relevant?

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 30 (4 by maintainers)

Commits related to this issue

Most upvoted comments

The possible reasons for the issues are

  1. Infinite recursion: recursive function call without a termination condition
  2. Importing Parent Module in childe module
  3. Mistakenly Self importing a module (see example)
@NgModule({
  imports: [
    TestModule
  ],
  declarations: [],
  exports: []
})
export class TestModule { }

Some other people reported that deleting their node_modules and re-installing got rid of this errorโ€ฆ can you try that?

as a WORKAROUND npm i terser@latest solved the issue for me. Installed the "terser": "^4.6.4",

Angular CLI: 9.0.4
Node: 10.16.2
OS: linux x64

Angular: 9.0.4
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router, service-worker
Ivy Workspace: Yes

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.900.4
@angular-devkit/build-angular     0.900.4
@angular-devkit/build-optimizer   0.900.4
@angular-devkit/build-webpack     0.900.4
@angular-devkit/core              9.0.4
@angular-devkit/schematics        9.0.4
@angular/cdk                      9.1.0
@angular/flex-layout              9.0.0-beta.29
@angular/material                 9.1.0
@ngtools/webpack                  9.0.4
@schematics/angular               9.0.4
@schematics/update                0.900.4
rxjs                              6.5.4
typescript                        3.7.5
webpack                           4.41.2

The answer of @kalimulhaq helps me, in my case, I was exporting my own module ๐Ÿ˜•

  declarations: [
    MyComponent
  ],
  imports: [
    CommonModule
  ],
  exports: [
    MyModule,    <---- My problem    
  ]
})
export class MyModule { }

Seta no angular.json โ€œaotโ€: false,

I had this error as well but in slightly different circumstances:

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / โ–ณ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 9.1.0
Node: 10.19.0
OS: win32 x64

Angular: 9.1.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Ivy Workspace: Yes

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.901.0
@angular-devkit/build-angular      0.901.0
@angular-devkit/build-ng-packagr   0.901.0
@angular-devkit/build-optimizer    0.901.0
@angular-devkit/build-webpack      0.901.0
@angular-devkit/core               9.1.0
@angular-devkit/schematics         9.1.0
@ngtools/webpack                   9.1.0
@schematics/angular                9.1.0
@schematics/update                 0.901.0
ng-packagr                         9.0.0
rxjs                               6.5.5
typescript                         3.7.5
webpack                            4.39.2

I was trying to build a prod library, this has to have ivy turned off. A library build with Ivy was fine. I tried all the various fixes listed here but nothing helped.

In the end I discovered that barrel files broke it for me.

This code worked fine:

// public-api.ts
export * from './my-module.module';
export * from './constants/constants';

(constants just exports 2 strings)

This code fails:

// public-api.ts
export * from './my-module.module';
export * from './constants';

(exports an index.ts file that just exports * from constants)

The workaround I found was to directly export every file in public.api and avoid barrels. The npm lib barrelsby helped a lot with this:

barrelsby -e .spec.ts -D true -l top -n public.api

In my case, it happens only once, too. When I retry building again, it works without any problem, even if I havenโ€™t done anything. Thatโ€™s why, some of these solutions may be misleading. ๐Ÿค”