8

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Error when running command: ionic cordova build android --prod

Note: that ionic build android, ionic run android and ionic serve all works fine.

I've read many topics that says once the project gets bigger, it stops working.

It was working the day before issue arrive. It stopped working as we added more files and JSON for translation of app in multi-language.

Is it a known issue? Is there any solution?

PLEASE CHECK FOR MORE DETAIL : https://youtu.be/oCN7iSt8rzg

Attached Error Image:

enter image description here

Ionic Info:

enter image description here

14
  • Even after --max_old_space_size it dont work, then it could be possible issue with the code. In security context section, it says error related to toString() So you may have to check the code where you are trying to do toString() of large object. This post should probably help - github.com/nodejs/node/issues/10137 Commented Jul 7, 2017 at 14:58
  • Try to increase memory limit to --max-old-space-size=8192 . Commented Jul 8, 2017 at 10:37
  • @Manish - (Thanks!) I tried, not working. Commented Jul 8, 2017 at 13:36
  • @Gandhi - (Thanks!) I didn't added any toString() but yes we have added large files containing JSON object (for translation of app in multi-language) is that causing problem? If yes - What would be the solution? Commented Jul 8, 2017 at 13:38
  • @AnkitMaheshwari you may try increasing your --max-old-space-size limit to further higher limit and give it a try. You can also try to out library like memwatch - github.com/marcominetti/node-memwatch to figure out the memory leaks. Commented Jul 8, 2017 at 16:49

4 Answers 4

8

Resolved by modifying my ionic.cmd file in C:\Users\AppData\Roaming\npm by adding --max_old_space_size. I set mine to 8096.

@if EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=8096 "%~dp0\node_modules\ionic\bin\ionic" %*
) ELSE (
@SETLOCAL
@set PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=8096 "%~dp0\node_modules\ionic\bin\ionic" %*
)

Good luck! Check Actual Source: https://github.com/ionic-team/ionic-cli/issues/1453

Sign up to request clarification or add additional context in comments.

6 Comments

Glad you tweaked it. Have posted my view as answer. Please accept if it was helpful. Cheers
Did you had a look at this?
@Gandhi I will look at this and try if things workout.
Thanks for the response. Accept answer if it was helpful
Any update on this as bounty seems to be running out?
|
2

My ionic (Ionic CLI) : 3.20.0 and @ionic/app-scripts : 3.1.8 but was still getting the error.

I fixed the error by updating the build script in package.json

  "scripts": {
    "clean": "ionic-app-scripts clean",
    "build": "node --max-old-space-size=2048 ./node_modules/.bin/ionic-app-scripts build",
    "lint": "ionic-app-scripts lint",
    "ionic:build": "ionic-app-scripts build",
    "ionic:serve": "ionic-app-scripts serve"
  },

or

Try the below command:

$ sudo node --max-old-space-size=4096 /usr/local/bin/ionic cordova build android --prod

4 Comments

i too getting the same issue My ionic (Ionic CLI) : 3.20.0 and @ionic/app-scripts : 3.1.9 and then i tried with your answer but still the error is coming, i have installed angularfire2(5.0.0.-rc.6) i think this is causing the memory leak in my app, i removed angularfire2 then i tried it worked, but now i want to use angularfire2 and also i want to build my app in --prod mode, please help me in this @Biranchi
@Midhunsai Try the below command, $sudo node --max-old-space-size=8192 /usr/local/bin/ionic cordova build android --prod
@Midhunsai: I have the same problems, do you find any solution/ workaround?
@Midhunsai, Try installing the node version v6.14.0 and check if it works.
1

I also encountered this error and I told myself that increasing the allocated memory was a workaround as something must be going wrong under the hood.

If you are using Firebase, it turns out that it is the culprit.

I changed it from "^4.12.1" to "4.6.1" (without the caret symbol) and ran npm install to downgrade it to the said anterior version.

After that, I was able to run ionic cordova build android --prod without encountering the dreaded "heap out of memory" error.

Apparently, 4.12.1 (and perhaps others) has a memory leak, hence the encountered issue.

Hope this helps!

Comments

0

Even though the issue is resolved by the OP, it's a temporary workaround. The actual issue is something to do with the string operations that is involved in the project.

As the OP has already mentioned that the project involves JSON strings of huge size, the ideal fix will be track down the memory consumption during build using tools like node-memwatch and fix the same. Setting heap size of approximately 8GB may not be possible all the time and this has to increase with the further enhancements in the project too.

Also as per this link, the latest webpack release will hopefully ease out some of these problems.

UPDATE: you can also try using latest Ionic CLI version 3.5.0 which may have some improvements

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.