Open ValterSantosMatos opened 7 years ago
Found a better solution, to specify NODE env variable before the build: export NODE_OPTIONS=--max-old-space-size=4096
Credits to: https://stackoverflow.com/a/48895989/4919972
Thanks @speedfl, my issue is also a big app. Maybe would be useful to debug if we could find a way to quantify what a "big" app is... Dunno if running the ionic build command with --verbose could also output the bundle size. Waiting for the Ionic team for some feedback on this. Btw the way we solve it is:
- add this to the package.json scripts
"ionic:build": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",
- run the command:
npm run ionic:build --prod
- run the commands:
cordova build android --release
cordova build ios --release
None of the options worked, Even if you put all the available memory in the computer, the error happens
@pascalwhoop I think the reason this isn't being investigated is that it's a wide range of issues that culminate to cause this. It was investigated by the Firebase team and ultimately deemed to be an Ionic issue that Firebase is inadvertently causing. This seems to have been corrected (for me anyway) by using this solution that I documented, a few comments above.
I have used your solution, but sadly seems that I am stuck in another issue, doesn't matter if I do --prod --release or anything, the IOS version does not release the .xcodeproj
file.
What do know what else to do.
This did the magic for me:
node --max-old-space-size=4096 $(which ionic) cordova build android --prod --aot --minifyjs --minifycss --optimizejs
After spending so much time on searching here and there to tackle this issue I came across this thread and with the help of some above comments I was able to resolve it. Here are the detailed steps along with the images which I did:
I went to: Users ▸ {YourUser} ▸ GitHub ▸ {YourIonicAppPath} ▸ node_modules ▸ @ionic ▸ app-scripts ▸ bin
Removed the first line: "#!/usr/bin/env node" and replaced it with:
#!/usr/bin/env node --max-old-space-size=4096
After making the above change I was able to build the ionic app for both the platforms without any error:
ionic cordova build ios --prod --release
ionic cordova build android --prod --release
At very this moment I have the following versions:
ionic -v: CLI 4.6.0 node -v: 10.14.2 npm -v: 6.4.1 cordova -v: 8.1.2
I managed to fix this by increasing the max RAM available to the node process: (On macOS) put this in your ~/.bashrc
export NODE_OPTIONS=--max_old_space_size=2048
And open a new terminal to make sure the settings have been set by executing echo $NODE_OPTIONS. Just make sure you don't overdo it/have enough RAM left for your other applications.
After spending so much time on searching here and there to tackle this issue I came across this thread and with the help of some above comments I was able to resolve it. Here ate the detailed steps along with the images which I did:
I went to: Users ▸ {YourUser} ▸ GitHub ▸ {YourIonicAppPath} ▸ node_modules ▸ @Ionic ▸ app-scripts ▸ bin
Removed the first line: "#!/usr/bin/env node" and replaced it with:
#!/usr/bin/env node --max-old-space-size=4096
After making the above change I was able to build the ionic app for both the platforms without any error:
ionic cordova build ios --prod --release
ionic cordova build android --prod --release
At very this moment I have the following versions:
ionic -v: CLI 4.6.0 node -v: 10.14.2 npm -v: 6.4.1 cordova -v: 8.1.2
If you are using a CI environment, then this solution will not work. We need a permanent fix for this from the Ionic team. Again, solutions exist to bypass this issue, but once you automate your builds stuff gets complicated. Our current solution is to fix @firebase/database to version 0.2.1 and wait for an Ionic fix.
For my app I found the critic threshold. Just removing some comment in my html files maked the build working. Keeping them maked the build failed
A little bit awkward but I confirm that html comment can create memory leak
I'm seeing this issue but when I build the browser version for prod.
We have multiple apps the share the node_modules folder. Two other apps browser build for production worked this one failed.
removed node_modeules and add them back. removed browser platform and added it back.
This app is on the smaller size compared to our others ones.
Update the max old space didn't not seem to fix it.
nothing of all solutions worked for me.... i dont have a large app or html comments either...
I am trying to create the ionic build with Jenkins getting error with command ENV=staging ionic cordova build browser --aot --prod JavaScript heap out of memory jenkin build can anyone help??
Can anyone please tell that how to resolve the JavaScript heap out of memory issue in ionic 5 as it does not have @ionic/app-scripts. How to resolve this issue? Any help would be appreciated.
Hello I just spent hours to understand what was the origin of the issue for me. The problem is maybe due to two things:
- presence of
"ionic_source_map_type": "#inline-source-map"
=> this needs to be removed before build prod- a huge app (with lot of pages) . This was my last case.
I tried several stuff like:
#!/usr/bin/env node --max-old-space-size=4096
in the ionic-app-scripts.js and other stuff (I don't remember because I tried so many stuff)The only which worked for me. Modify:
node_modules/.bin/ionic-app-scripts.cmd
By adding:
@IF EXIST "%~dp0\node.exe" ( "%~dp0\node.exe" "%~dp0\..\@ionic\app-scripts\bin\ionic-app-scripts.js" %* ) ELSE ( @SETLOCAL @SET PATHEXT=%PATHEXT:;.JS;=;% node --max_old_space_size=4096 "%~dp0\..\@ionic\app-scripts\bin\ionic-app-scripts.js" %* )
I am on windows. So if you are on linux I guess you have to modify
node_modules/.bin/ionic-app-scripts
with this:#!/bin/sh basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") case `uname` in *CYGWIN*) basedir=`cygpath -w "$basedir"`;; esac if [ -x "$basedir/node" ]; then "$basedir/node --max_old_space_size=4096" "$basedir/../@ionic/app-scripts/bin/ionic-app-scripts.js" "$@" ret=$? else node --max_old_space_size=4096 "$basedir/../@ionic/app-scripts/bin/ionic-app-scripts.js" "$@" ret=$? fi exit $ret
However this is a tweak. It could be nice to pass this environment variable like this:
ionic build android --prod --release --max_old_space_size=4096
Last thing. In some cases it is
--max_old_space_size
and for other it is--max-old-space-size
based on your node version. To check the format you can typenode --v8-options
Keep me posted if it is working for you.
work fine for me, many thanks
Hi there,
I read in another issue that this should had been solved, before so I tried removing the:
"node --max-old-space-size=8192
workaround from my project but still have the same problem. The stack-trace and ionic info bellow. Let me know if anything else is needed.ionic info
global packages:
local packages:
System:
ionic cordova build ios --prod --verbose
[DEBUG] Loading global plugin @ionic/cli-plugin-proxy [DEBUG] Throwing PLUGIN_NOT_INSTALLED for global @ionic/cli-plugin-proxy [DEBUG] Loading local plugin @ionic/cli-plugin-cordova [DEBUG] Loading local plugin @ionic/cli-plugin-ionic-angular Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser
[20:08:46] build prod started ... [20:08:46] clean started ... [20:08:46] clean finished in 1 ms [20:08:46] copy started ... [20:08:46] ngc started ... [20:09:19] ngc finished in 32.84 s [20:09:19] preprocess started ... [20:09:19] deeplinks started ... [20:09:22] deeplinks finished in 3.67 s [20:09:22] optimization started ... [20:09:39] copy finished in 52.56 s [20:10:04] optimization finished in 41.73 s [20:10:04] preprocess finished in 45.40 s [20:10:04] webpack started ...
<--- Last few GCs --->
402717 ms: Mark-sweep 1332.3 (1437.1) -> 1331.6 (1437.1) MB, 1137.5 / 0.0 ms [allocation failure] [GC in old space requested]. 403827 ms: Mark-sweep 1331.6 (1437.1) -> 1331.5 (1437.1) MB, 1109.4 / 0.0 ms [allocation failure] [GC in old space requested]. 404969 ms: Mark-sweep 1331.5 (1437.1) -> 1340.4 (1421.1) MB, 1141.3 / 0.0 ms [last resort gc]. 406115 ms: Mark-sweep 1340.4 (1421.1) -> 1349.5 (1421.1) MB, 1145.4 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3253a08cfb51
2: / anonymous / [/Users/Valter/projects/8sec-front-end/node_modules/source-map/lib/source-node.js:~80] [pc=0x40b1c23c541] (this=0x9c85c680801 <JS Function SourceNode (SharedFunctionInfo 0xd26940f131)>,mapping=0x392f564c03b1 <an Object with map 0xc6fc3d4d9f9>)
3: arguments adaptor frame: 3->1
4: InnerArrayForEach(aka InnerArrayForEach) [native array.js:~935] [pc=0x40b1becab8b] (th...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory 1: node::Abort() [/usr/local/bin/node] 2: node::FatalException(v8::Isolate, v8::Local, v8::Local) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const , bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewUninitializedFixedArray(int) [/usr/local/bin/node]
5: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::ConvertElementsWithCapacity(v8::internal::Handle, v8::internal::Handle, v8::internal::ElementsKind, unsigned int, unsigned int, unsigned int, int) [/usr/local/bin/node]
6: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacityAndConvertImpl(v8::internal::Handle, unsigned int) [/usr/local/bin/node]
7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object*, v8::internal::Isolate) [/usr/local/bin/node]
8: 0x40b17d079a7
9: 0x40b17d2e9c5
10: 0x40b1c23c541
Abort trap: 6