Getting Module build failed: RangeError: Maximum call stack size exceeded after upgrade to Ionic 3

I have just gone upgraded my Ionic 2 app to Ionic 3, all of framework, Ionic native, and the CLI.

I now have the following setup…

		"dependencies": {
			"@angular/animations": "4.1.0",
			"@angular/common": "4.1.0",
			"@angular/compiler": "4.1.0",
			"@angular/compiler-cli": "4.1.0",
			"@angular/core": "^4.1.0",
			"@angular/forms": "4.1.0",
			"@angular/http": "^4.1.0",
			"@angular/platform-browser": "4.1.0",
			"@angular/platform-browser-dynamic": "4.1.0",
			"@ionic-native/app-version": "^3.8.0",
			"@ionic-native/core": "3.6.1",
			"@ionic-native/device": "^3.8.0",
			"@ionic-native/file": "^3.7.0",
			"@ionic-native/network": "^3.8.0",
			"@ionic-native/social-sharing": "^3.7.0",
			"@ionic-native/splash-screen": "3.6.1",
			"@ionic-native/status-bar": "3.6.1",
			"@ionic-native/toast": "^3.8.0",
			"@ionic/storage": "2.0.1",
			"c3": "git://github.com/masayuki0812/c3.git",
			"ionic-angular": "3.2.1",
			"ionicons": "3.0.0",
			"js-logger": "^1.3.0",
			"jslogger": "^1.0.3",
			"jszip": "^3.1.3",
			"lodash": "^4.17.4",
			"moment": "^2.17.1",
			"moment-duration-format": "^1.3.0",
			"ng2-translate": "^5.0.0",
			"rxjs": "5.1.1",
			"semaphore-async-await": "^1.3.2",
			"sw-toolbox": "3.6.0",
			"zone.js": "0.8.10"
		  },
		  "devDependencies": {
			"@ionic/app-scripts": "1.3.7",
			"@ionic/cli-plugin-ionic-angular": "1.0.0",
			"@types/c3": "^0.4.38",
			"@types/jasmine": "^2.5.42",
			"@types/jszip": "0.0.32",
			"@types/lodash": "^4.14.51",
			"@types/moment-duration-format": "^1.3.1",
			"@types/node": "^7.0.5",
			"codecov": "^1.0.1",
			"install": "^0.8.7",
			"jasmine-core": "^2.5.2",
			"jasmine-spec-reporter": "^3.2.0",
			"karma": "^1.4.1",
			"karma-chrome-launcher": "^2.0.0",
			"karma-jasmine": "^1.1.0",
			"karma-mocha-reporter": "^2.2.2",
			"karma-remap-istanbul": "^0.6.0",
			"ts-node": "^2.1.0",
			"tslint": "^4.4.2",
			"tslint-eslint-rules": "^3.3.0",
			"typescript": "^2.2.1"
		  },

Now, if I build with the -prod flag (it id fine without this), I get the following error…

[16:50:08]  webpack started ...
Error: ./~/jszip/lib/index.js
Module build failed: RangeError: Maximum call stack size exceeded
    at Object.forEachChild (D:\dev\myapp\node_modules\typescript\lib\typescript.js:14735:26)
    at traverse (D:\dev\myapp\node_modules\typescript\lib\typescript.js:7271:31)
    at Object.forEachReturnStatement (D:\dev\myapp\node_modules\typescript\lib\typescript.js:7251:16)
    at checkAndAggregateReturnExpressionTypes (D:\dev\myapp\node_modules\typescript\lib\typescript.js:40055:16)
    at getReturnTypeFromBody (D:\dev\myapp\node_modules\typescript\lib\typescript.js:39965:29)
    at getReturnTypeOfSignature (D:\dev\myapp\node_modules\typescript\lib\typescript.js:31190:28)
    at resolveNewExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:39483:21)
    at resolveSignature (D:\dev\myapp\node_modules\typescript\lib\typescript.js:39639:28)
    at getResolvedSignature (D:\dev\myapp\node_modules\typescript\lib\typescript.js:39669:26)
    at checkCallExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:39696:29)
 @ ./src/providers/file-logger.ts 58:0-28
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts,./~/d3/d3.js
Module build failed: RangeError: Maximum call stack size exceeded
    at RegExp.[Symbol.replace] (native)
    at String.replace (native)
    at formatStringFromArgs (D:\dev\myapp\node_modules\typescript\lib\typescript.js:2365:21)
    at Object.chainDiagnosticMessages (D:\dev\myapp\node_modules\typescript\lib\typescript.js:2433:20)
    at reportNonexistentProperty (D:\dev\myapp\node_modules\typescript\lib\typescript.js:38290:28)
    at checkPropertyAccessExpressionOrQualifiedName (D:\dev\myapp\node_modules\typescript\lib\typescript.js:38332:
21)
    at checkPropertyAccessExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:38274:20)
    at checkExpressionWorker (D:\dev\myapp\node_modules\typescript\lib\typescript.js:41158:28)
    at checkExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:41115:42)
    at checkExpressionWithContextualType (D:\dev\myapp\node_modules\typescript\lib\typescript.js:40983:26)
 @ ./src/pages/mypage/mypage.ts 61:0-25
 @ ./src/app/app.module.ts
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts

It seems to not be liking the jszip , and even mkore suprisingly something to do with RegExp The only place I use RegExp is as follows

let regExStrip0 = /(\.0+)+$/;
let segmentsA = a.replace(regExStrip0, '').split('.');
let segmentsB = b.replace(regExStrip0, '').split('.');
...

Does anyone know why I now get this error, and know any work around?

Thanks in advance!

Does removing the RegEx stuff make the app build with --prod?

1 Like

I commented out the RegEx, but I still get the error from other places…

[19:32:35]  optimization started ...
[19:32:35]  copy finished in 10.19 s
[19:32:49]  optimization finished in 14.02 s
[19:32:49]  preprocess finished in 14.58 s
[19:32:49]  webpack started ...
Error: ./~/jszip/lib/index.js
Module build failed: RangeError: Maximum call stack size exceeded
    at traverse (D:\dev\myapp\node_modules\typescript\lib\typescript.js:7252:26)
    at visitNode (D:\dev\myapp\node_modules\typescript\lib\typescript.js:14712:20)
    at Object.forEachChild (D:\dev\myapp\node_modules\typescript\lib\typescript.js:14909:24)
    at traverse (D:\dev\myapp\node_modules\typescript\lib\typescript.js:7271:31)
    at visitEachNode (D:\dev\myapp\node_modules\typescript\lib\typescript.js:14724:30)
    at Object.forEachChild (D:\dev\myapp\node_modules\typescript\lib\typescript.js:14896:24)
    at traverse (D:\dev\myapp\node_modules\typescript\lib\typescript.js:7271:31)
    at Object.forEachReturnStatement (D:\dev\myapp\node_modules\typescript\lib\typescript.js:7251:16)
    at checkAndAggregateReturnExpressionTypes (D:\dev\myapp\node_modules\typescript\lib\typescript.js:40055:16)
    at getReturnTypeFromBody (D:\dev\myapp\node_modules\typescript\lib\typescript.js:39965:29)
 @ ./src/providers/file-logger.ts 58:0-28
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts,./~/d3/d3.js
Module build failed: RangeError: Maximum call stack size exceeded
    at getSymbolLinks (D:\dev\myapp\node_modules\typescript\lib\typescript.js:26017:32)
    at getTypeOfFuncClassEnumModule (D:\dev\myapp\node_modules\typescript\lib\typescript.js:29402:25)
    at getTypeOfSymbol (D:\dev\myapp\node_modules\typescript\lib\typescript.js:29484:24)
    at checkIdentifier (D:\dev\myapp\node_modules\typescript\lib\typescript.js:36214:24)
    at checkExpressionWorker (D:\dev\myapp\node_modules\typescript\lib\typescript.js:41135:28)
    at checkExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:41115:42)
    at getTypeOfExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:41086:58)
    at narrowTypeByInstanceof (D:\dev\myapp\node_modules\typescript\lib\typescript.js:35957:33)
    at narrowTypeByBinaryExpression (D:\dev\myapp\node_modules\typescript\lib\typescript.js:35854:32)
    at narrowType (D:\dev\myapp\node_modules\typescript\lib\typescript.js:36067:32)
 @ ./src/pages/mypage/mypage.ts 61:0-25
 @ ./src/app/app.module.ts
 @ ./src/app/app.module.ngfactory.ts
 @ ./src/app/main.ts

If you comment out that stuff, does the app build then? Let’s first get all the problem there are identified.

Ok, good idea. …
So I can get the app to build if I comment out the following three things…

a. The use of string.replace…

let regExStrip0 = /(\.0+)+$/;
let segmentsA = a.replace(regExStrip0, '').split('.');
let segmentsB = b.replace(regExStrip0, '').split('.');

b. The jszip lib
c. The C3/D3 graphing library.

So I wonder why they are causing problems, where they didn’t before?

Good question.

Next I would downgrade the CLI to 2.2.3 as this is easiest to do and see if it builds then. If not, go back to the current CLI version.

And then I am out of ideas as I don’t know nearly enough about the build process. You should probably create an issue with Ionic app-scripts on Github then.

Thanks for that. I went back to 2.2.3 but still had the same issue. I also realised that there was not problem with the string.replace, I could include that code as long as I had the C3/D3 and jszip removed (or at least it seemed to go away for now).

If I use either of these libs in a blank newly created Ionic project, then I do not get the problem, but that doesn’t help me to track why they are a problem in my project (perhaps because it is bigger)

I may have to raise the issue, even though I plan to go away from the C3/D3 soon, I still need it just for now (as I do the jszip)

Added a build issue here.

1 Like

Similar error when running ionic cordova build browser --prod after uptdate from Ionic 3.2.1 to 3.3.0. It only happens when I use --prod parameter.

Error log:

$ ionic cordova build browser --prod
Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

    [13:22:25]  build prod started ...
    [13:22:25]  clean started ...
    [13:22:25]  clean finished in 16 ms
    [13:22:25]  copy started ...
    [13:22:25]  ngc started ...
    [13:22:37]  ngc finished in 11.64 s
    [13:22:37]  preprocess started ...
    [13:22:37]  deeplinks started ...
    [13:22:37]  deeplinks finished in 594 ms
    [13:22:37]  optimization started ...
    [13:22:38]  copy finished in 12.65 s
    [13:22:57]  optimization finished in 19.56 s
    [13:22:57]  preprocess finished in 20.15 s
    [13:22:57]  webpack started ...
    [WARN] Error occurred during command execution from a CLI plugin (@ionic/cli-plugin-cordova). Your plugins may be out of date.
    Error: ./~/d3/d3.js
    Module build failed: RangeError: Maximum call stack size exceeded
        at checkNonNullExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:38397:40)
        at checkPropertyAccessExpressionOrQualifiedName (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:38455:24)
        at checkPropertyAccessExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:38413:20)
        at checkExpressionWorker (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:41300:28)
        at checkExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:41257:42)
        at checkBinaryLikeExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:40834:28)
        at checkBinaryExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:40827:20)
        at checkExpressionWorker (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:41335:28)
        at checkExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:41257:42)
        at checkBinaryLikeExpression (C:\Projetos\MyProject\Frontend\node_modules\typescript\lib\typescript.js:40834:28)
     @ ./~/c3/c3.js 830:70-83
     @ ./src/components/c3-chart-component/c3-chart-adapter.ts
     @ ./src/components/c3-chart-component/c3-chart-component.ts
     @ ./src/pages/dashboard/dashboard.ngfactory.ts
     @ ./src/pages/dashboard/dashboard.module.ngfactory.ts
     @ ./src async
     @ ./~/ionic-angular/util/ng-module-loader.js
     @ ./src/app/app.module.ngfactory.ts
     @ ./src/app/main.ts

Any solution to this? I have the same problem, but only when building for iOs on MacOs, android in Windows builds OK. Issue only appears if I build with --prod flag.

cli packages:
@ionic/cli-plugin-cordova : 1.6.2
@ionic/cli-plugin-ionic-angular : 1.4.1
@ionic/cli-utils : 1.7.0
ionic (Ionic CLI) : 3.7.0
global packages:
Cordova CLI : 7.0.1
local packages:
@ionic/app-scripts : 2.1.3
Cordova Platforms : android 6.2.3 ios 4.3.1
Ionic Framework : ionic-angular 3.6.0
System:
Node : v6.9.3
OS : macOS Sierra
Xcode : Xcode 8.3.3 Build version 8E3004b
ios-deploy : 1.9.0
npm : 3.10.10

nevermind, solved it by reinstalling “npm install d3” and adding “–max_old_space_size=4096” to “ionic-app-scripts build --prod”

1 Like