1

I am able to add --max_old_space_size in Android for release build in React Native. However, I am not able to add it for the iOS build release. I found the answer but it is not working.

React Native build fails with "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory"

Here is some useful link:

React Native ios build : Can't find node

If you have any suggestions, please let me know. I am willing to hear from you guys.

Thank you in advance!

Luong Truong
  • 1,953
  • 2
  • 27
  • 46

3 Answers3

2

The answer is in this link:

Javascript out of memory heap

Change:

shellScript = "export NODE_BINARY=node\n../node_modules/react-native/scripts/react-native-xcode.sh";

To:

shellScript = "export NODE_BINARY='node --max_old_space_size=8192'\n../node_modules/react-native/scripts/react-native-xcode.sh";

In:

ios/YourProjectName.xcodeproj/project.pbxproj

Please be patient because the project cost a lot of time when build release. More than 10 minutes.

Luong Truong
  • 1,953
  • 2
  • 27
  • 46
2

By adding Max_old_heap_size in xcode you can resolve.

Please Check the attachment

Abhilash K
  • 76
  • 5
1

Add Max-old-space-size at react-native-xcode.sh

[ -z "$NODE_BINARY" ] && export NODE_BINARY="node"

[ -z "$NODE_ARGS" ] && export NODE_ARGS="--max-old-space-size=4096"

[ -z "$CLI_PATH" ] && export CLI_PATH="$REACT_NATIVE_DIR/cli.js"

[ -z "$BUNDLE_COMMAND" ] && BUNDLE_COMMAND="bundle"

Abhilash K
  • 76
  • 5
  • thank you for your answer. The `react-native-xcode.sh` is belonged to node_modules folder, which will be removed if we type `npm install`. Your answer is worked but it is not 100% safe – Luong Truong Mar 13 '19 at 06:33
  • I cannot see the attachment, you must have at least 10 reputation point to upload image if I remember correctly – Luong Truong Mar 13 '19 at 07:43
  • Can you check now? – Abhilash K Mar 13 '19 at 07:44
  • I see it now. I will have a try on it, bro. But this solution is only for release – Luong Truong Mar 13 '19 at 07:45
  • node --max-old-space-size=4096 node_modules/react-native/local-cli/cli.js start – Abhilash K Mar 13 '19 at 07:48
  • While I agree this answer is slightly unsafe its the ONLY one that actually worked for me. Changing the build scripts did nothing to help the failure of xcode archiving which was failing due to memory issues. Only changing the underlying package script to include the help size worked. Will have to keep a manual note to re-add anytime we change a package on imac build server. Yay..... – Mark Lloyd May 21 '21 at 03:04