Error in ionic cordova build android --prod

耗尽温柔 提交于 2019-12-04 04:28:05

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

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

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!

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!