ng-packagr: Maximum Call Stack Size Exceeded with version 5

Type of Issue

[X] Bug Report
[ ] Feature Request

Description

After upgrading to ng-packagr 5 I see the following output for a project that builds fine with v4:

BUILD ERROR
Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:355:21)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)
    at MetadataBundler.convertValue (C:\d\ContentHub\prod-wch-sdk-ng7\utils\node_modules\@angular\compiler-cli\src\metadata\bundler.js:372:36)

Downgrading to v4 solves this, without and further changes.

My dependencies:

  "dependencies": {
    "@ibm-wch-sdk/api": "7.2.601",
    "loose-envify": "^1.4.0"
  },
  "devDependencies": {
    "@angular/cli": "^7.3.7",
    "@angular/compiler": "^7.2.11",
    "@angular/compiler-cli": "^7.2.11",
    "@angular/core": "^7.2.11",
    "@angular/language-service": "^7.2.11",
    "@types/jest": "^23.3.5",
    "@types/node": "^11.12.0",
    "core-js": "^3.0.0",
    "cpx": "^1.5.0",
    "jest": "^23.6.0",
    "exitzero": "^1.0.1",
    "jsdom": "^13.2.0",
    "lucene": "^2.0.1",
    "ng-packagr": "^5.0.1",
    "npm-run-all": "^4.1.5",
    "requestidlecallback": "^0.3.0",
    "rimraf": "^2.6.3",
    "rxjs": "~6.3.3",
    "rxjs-marbles": "^3.0.1",
    "rxjs-tslint-rules": "^4.11.0",
    "sync-files": "^1.0.3",
    "tools-helper-merge-markdown": "^0.1.112",
    "ts-jest": "^23.10.4",
    "ts-node": "^8.0.3",
    "tsickle": "^0.34.3",
    "tslib": "^1.9.3",
    "tslint": "^5.14.0",
    "tslint-sonarts": "^1.7.0",
    "typedoc": "^0.13.0",
    "typedoc-plugin-markdown": "^1.1.17",
    "typescript": "~3.2.2",
    "url-search-params-polyfill": "^3.0.0",
    "uuid": "^3.3.2",
    "zone.js": "^0.8.29"
  },

This looks similar to #1093 but in my case I am not referencing any barrel files, all imports are referenced via direct file references.

Is there anything in the logging I can do to nail down the problem?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 21 (7 by maintainers)

Most upvoted comments

Maximum call stack size exceeded
RangeError: Maximum call stack size exceeded
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:1:1)
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:366:36)
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:366:36)
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:366:36)
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:366:36)
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:366:36)
    at MetadataBundler.convertValue (/src/node_modules/@angular/compiler-cli/src/metadata/bundler.js:366:36)

code that produces error

export function generateUuid(): string {
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c: string): string {
    const r = (Math.random() * 16) | 0,
      v = c === 'x' ? r : (r & 0x3) | 0x8;
    return v.toString(16);
  });
}

working code

export function generateUuid(): string {
  const uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
    /[xy]/g,
    (c: string): string => {
      const r = (Math.random() * 16) | 0,
        v = c === 'x' ? r : (r & 0x3) | 0x8;
      return v.toString(16);
    },
  );

  return uuid;
}

environment mhart/alpine-node:10

Angular CLI: 7.3.5
Node: 10.15.1
OS: darwin x64
Angular: 7.2.8
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... platform-server, router

Package                            Version
------------------------------------------------------------
@angular-devkit/architect          0.13.5
@angular-devkit/build-angular      0.13.5
@angular-devkit/build-ng-packagr   0.13.5
@angular-devkit/build-optimizer    0.13.5
@angular-devkit/build-webpack      0.13.8
@angular-devkit/core               7.3.5
@angular-devkit/schematics         7.3.5
@angular/cdk                       7.3.7
@angular/cli                       7.3.5
@ngtools/json-schema               1.1.0
@ngtools/webpack                   7.3.5
@schematics/angular                7.3.5
@schematics/update                 0.13.5
ng-packagr                         5.1.0
rxjs                               6.4.0
typescript                         3.2.4
webpack                            4.29.0

Hi, I tried this locally, and it seems that the issue is related to the node version, when I used Node 10.10 it failed however when using Node 11 it worked as expected.

Screenshot 2019-03-31 at 12 50 51

I didn’t find the root cause of this issue though.

Same error:

[error] RangeError: Maximum call stack size exceeded
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:404:59)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)
    at MetadataBundler.convertValue ([myproject]/node_modules/@angular/compiler-cli/src/metadata/bundler.js:422:36)

> ng "--version"


     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 9.0.4
Node: 12.16.1
OS: linux x64

Angular: 9.0.4
... 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.900.4
@angular-devkit/build-angular      0.900.4
@angular-devkit/build-ng-packagr   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
@ngtools/webpack                   9.0.4
@schematics/angular                9.0.4
@schematics/update                 0.900.4
ng-packagr                         9.0.2
rxjs                               6.5.4
typescript                         3.7.5
webpack                            4.41.2

Also tried it on Node 10. Same error.

Deleting node_modules folder and re-installing all deps fixes the issue.. Although trying to run build the second time results in an error again.

By the way, if you are facing this issue as well and do not have the ability to switch to a different Node js version, you can try to downgrade the ng-packagr.

"ng-packagr": "^4.7.0", works for me in our project. The ng update command will install the latest packagr version, so you need to check this after upgrading.

Hi, I am not quite sure what is your error. you didn’t provide much information. I suggest you open a new issue and provided all the necessary information unless the error you are seeing is Maximum call stack size exceeded RangeError: Maximum call stack size exceeded at MetadataBundler.convertValue.

I added some console logs to the angular compiler and found that apparently the following line causes the issue:

export function flattenArray<T>(aArray: T[][]): T[] {
  return [].concat(...aArray);
}

after patching to

export function flattenArray<T>(aArray: T[][]): T[] {
  // return [].concat(...aArray);
  return undefined;
}

the complete project compiles.