react-native: [Bundle] "Allocation failed - process out of memory" in OSX making bundle
I get an error archiving iOS app, while react-native-xcode.sh is running.
I have found the command which throw the error:
$ react-native bundle --entry-file index.ios.js --platform ios --dev false --bundle-output /Users/matteo/Library/Developer/Xcode/DerivedData/XXX-giksyrhhnbtkzvexaglpgclnuxxc/Build/Intermediates/ArchiveIntermediates/XXX/BuildProductsPath/Release-iphoneos/XXX.app/main.jsbundle --assets-dest /Users/matteo/Library/Developer/Xcode/DerivedData/XXX-giksyrhhnbtkzvexaglpgclnuxxc/Build/Intermediates/ArchiveIntermediates/XXX/BuildProductsPath/Release-iphoneos/XXX.app --verbose
Output:
ReactNativePackager:SocketClient connecting to +0ms /var/folders/vf/51_gzv_93q5dv1zcs0m_8vkr0000gn/T/react-packager-5aca564e0b1dba4dc62417c52f2469f6
bundle: Created ReactPackager
ReactNativePackager:SocketClient got message with type +859ms result
bundle: start
[14:01:19] <START> Whole Program Optimisations
<--- Last few GCs --->
15879 ms: Scavenge 1398.4 (1455.5) -> 1398.4 (1455.5) MB, 0.8 / 0 ms (+ 2.0 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
16864 ms: Mark-sweep 1398.4 (1455.5) -> 1396.3 (1455.5) MB, 984.7 / 0 ms (+ 3.5 ms in 2 steps since start of marking, biggest step 2.0 ms) [last resort gc].
17817 ms: Mark-sweep 1396.3 (1455.5) -> 1398.2 (1455.5) MB, 953.2 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x1ab707fe3ac1 <JS Object>
1: get [/Users/matteo/mobile-workspace/XXX/node_modules/babel-traverse/lib/path/index.js:~75] [pc=0x26d5471a2791] (this=0x618f966b51 <JS Function NodePath (SharedFunctionInfo 0x36f8c2bcf7d1)>,_ref2=0x3de3985e7ca9 <an Object with map 0x2b945634e609>)
2: node [/Users/matteo/mobile-workspace/XXX/node_modules/babel-traverse/lib/index.js:~119] [pc=0x26d54711edf4] (this=0x618f967bf1 <JS F...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Abort trap: 6
My versions:
$ react-native -v
react-native-cli: 0.1.8
react-native: 0.17.0
$ node -v
v5.4.0
With DEV=true there are no problems.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 1
- Comments: 31 (12 by maintainers)
Okay, this is a dirty dirty hack, but after staring at the internals of the packager for several hours (and not understanding it) I’ve found a way to get the packager to complete a bundle.
edit
node_modules/babel-traverse/lib/index.js
and add this to the top of the file:Now you need to call the bundler like this (to enable garbage collection):
node --expose-gc --max_old_space_size=4096 "./node_modules/react-native/local-cli/cli.js" bundle --entry-file ./index.ios.js --platform ios --dev false --reset-cache true --bundle-output "MyApp.app/main.jsbundle" --assets-dest "MyApp.app"
NOTE: I’m not sure what the values are supposed to be for
--bundle-output
and -assets-dest`, but the key thing to note is the –expose-gc flag which allows this to work.So, what is this doing? For me at least, the bundler was running out of memory during babel transformation (or ast building?). Putting that code at the top of that file runs garbage collection every 30 seconds (might have to tune it depending on your machine). It seems to work well enough to stop V8 from running out of heap memory. But yes, it’s a dirty dirty hack.
In general, how do we fix this? Adding a fix value in the code seems not good. But calculating a possible value for memory size could be reasonable? Sth like:
if ram <= 4GB, use 2,5GB
if ram <= 8GB, use 4GB
else use 8GB
Another way could be to read if there is an environment var set and use it (which would be my favourite).
@Takeno Thanks for digging into this issue! Maybe you’d be interested to submit a PR to add a memory limit option, or at least to document the issue in the Troubleshooting section?
Hey Takeno, thanks for reporting this issue!
React Native, as you’ve probably heard, is getting really popular and truth is we’re getting a bit overwhelmed by the activity surrounding it. There are just too many issues for us to manage properly.
react-native
or for more real time interactions, ask on Discord in the #react-native channel.