question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Increasing node memory not possible when building straight from Xcode

See original GitHub issue

Environment

React Native Environment Info:
    System:
      OS: macOS 10.14
      CPU: x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
      Memory: 2.80 GB / 16.00 GB
      Shell: 5.6.1 - /usr/local/bin/zsh
    Binaries:
      Node: 9.11.2 - /usr/local/bin/node
      Yarn: 1.10.1 - /usr/local/bin/yarn
      npm: 5.6.0 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.0, macOS 10.14, tvOS 12.0, watchOS 5.0
      Android SDK:
        Build Tools: 25.0.1, 26.0.1, 26.0.3, 27.0.3, 28.0.0, 28.0.3
        API Levels: 23, 25, 26, 27, 28
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.0/10A255 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.0-alpha.8af6728 => 16.6.0-alpha.8af6728
      react-native: 0.57.3 => 0.57.3
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7

Description

I need to use the profiling tool in Xcode, which requires building the app from Xcode. My app requires extra memory. I can successfully build my app from the command line with node --expose-gc --max_old_space_size=4096 ./node_modules/react-native/local-cli/cli.js bundle [...], but I have to rewrite react-native-xcode.sh in order to get this working in Xcode. If I skip bundling entirely, Xcode complains that the bundle doesn’t exist. If I don’t increase the space manually in the script, Xcode hangs on Building 1 of 2 shell scripts (the shell script being react-native-xcode.sh, and then it runs out of memory (throws Allocation: JS heap out of memory).

I can either add in main.jsbundle manually, or edit the script. There doesn’t seem to be any real way to accomplish increasing node memory for Xcode without using a hack, or nothing I could find in old issues or documentation. There’s no obvious way of how to use the flags that exist in react-native-xcode.sh.

Somewhat related issues: #5196, #12686

Reproducible Demo

Run react-native init, open that project in Xcode, try to increase node memory. Obviously this works better if you have an app that requires more memory.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7

github_iconTop GitHub Comments

6reactions
marstankevcommented, Jun 5, 2019

@timkuilman Instead of modifying react-native-xcode.sh (which as you point out is temporary), you can specify NODE_ARGS in the Xcode, Target > Build Phases > Bundle React Native code and images script like so:

export NODE_BINARY=node
export NODE_ARGS="--max_old_space_size=8192"
../node_modules/react-native/scripts/react-native-xcode.sh

This was the only way I could get my productions builds working again, as passing in the memory allocation argument as suggested here and in other similar issues ( export NODE_BINARY='node --max_old_space_size=8192') did not solve the problem for me.

0reactions
timkuilmancommented, May 1, 2019

I was running into the same issue and found a work around. The extra arguments for node were not picked up when I added them in Xcode, Target > Build Phases > Bundle React Native code so I changed the following line in react-native-xcode.sh

[ -z "$NODE_ARGS" ] && export NODE_ARGS=""

to:

[ -z "$NODE_ARGS" ] && export NODE_ARGS="--max_old_space_size=4096"

I am not too familiar with shell script but I guess that the second NODE_ARGS in that line is the fallback?

npm install will overwrite these c hanges but at least I can make a release build now again. In my app the aws-sk package is also responsible for the out of memory error. @Blutude let me know if this helps you or if you have fixed the issue in another way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Xcode build causes memory issue | Apple Developer Forums
Given the fact that memory is swapping, the build takes a very long time and the computer is otherwise unusable. The computer becomes...
Read more >
Running out of memory in 'Other Processes' in Usage ...
To give an idea of what I'm doing, I'm pulling data from Parse, then looping through each of the objects returned and creating...
Read more >
Node.js v19.3.0 Documentation
Working with JavaScript values and abstract operations ... --no-global-search-paths; --no-warnings; --node-memory-debug ... Options for building Node.js.
Read more >
Microsoft-hosted agents for Azure Pipelines
You can try it first and see if it works for your build or deployment. If not, you can use a self-hosted agent....
Read more >
7 foolproof tips for iOS memory management using Swift and ...
How to debug and avoid memory issues · Override the dealloc method · Manually create autoreleasepools · Isolate possible problem areas.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found