react-native: Bundling large static assets results in Heap out of Memory

Hi All,

I am trying to bundle a react-native app for production, using the following command:

react-native bundle --reset-cache --entry-file index.ios.js --platform ios --dev false --bundle-output ios/main.

The react-native-app that I am building contains a lot of static assets, primarily videos–389 MB to be exact. When I am trying to bundle the app, I get the following output in the command line:

Loading dependency graph, done.
Warning: The transform cache was reset.

<--- Last few GCs --->

   51001 ms: Mark-sweep 1382.5 (1432.9) -> 1382.5 (1432.9) MB, 37.3 / 0.0 ms (+ 0.0 ms in 1 steps since start of marking, biggest step 0.0 ms) [allocation failure] [GC in old space requested].
   51039 ms: Mark-sweep 1382.5 (1432.9) -> 1382.4 (1432.9) MB, 38.8 / 0.0 ms [allocation failure] [GC in old space requested].
   51100 ms: Mark-sweep 1382.4 (1432.9) -> 1382.4 (1396.9) MB, 60.5 / 0.0 ms [last resort gc].
   51134 ms: Mark-sweep 1382.4 (1396.9) -> 1382.4 (1396.9) MB, 34.1 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x3880234cfb51 <JS Object>
    1: [Symbol.replace] [native regexp.js:~540] [pc=0x8ed7ac2d43c] (this=0x3c8b808497b1 <JS RegExp>,D=0x1777c0004201 <Very long string[11855109]>,aw=0x3880234ae4d1 <String[1]:  >)
    2: 0x38802348aaf1 <Symbol: 20329980 <String[14]: Symbol.replace>>(aka [Symbol.replace]) [native regexp.js:677] [pc=0x8ed7acf070a] (this=0x3c8b808497b1 <JS RegExp>,D=0x1777c0004201 <Very long string[11855109]>,aw=0...

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::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
 4: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
 5: v8::internal::ReplacementStringBuilder::ToString() [/usr/local/bin/node]
 6: v8::internal::Runtime_StringReplaceGlobalRegExpWithString(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
 7: 0x8ed7a7092a7
 8: 0x8ed7ac2d43c
 9: 0x8ed7acf070a
[1]    1938 abort      react-native bundle --reset-cache --entry-file index.ios.js --platform ios

I have referred the to following (closed) issue , but nothing seems to solve the problem. Since this issues is probably due to the size of the static assets, is there a way to manually add those assets to the Xcode project–without passing them through the bundler? Or, perhaps, there is another way around this issue? Any help will be greatly appreciated.

  • React Native version: [0.41.0]
  • Platform: [IOS]
  • Operating System: [MacOS]

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21 (1 by maintainers)

Most upvoted comments

I hit this during an upgrade from react-native 0.40.0 to 0.46.4. I cannot make this work, even with --max_old_space_size=16000

I have also tried with node 8.2.1. I’m getting:

node --expose-gc --max_old_space_size=16000 ./node_modules/react-native/local-cli/cli.js bundle --entry-file ./index.ios.js --platform ios --dev false --bundle-output "ios/main.jsbundle" --assets-dest "ios" --reset-cache
transform[stdout]:
transform[stdout]: <--- Last few GCs --->
transform[stdout]:
transform[stdout]: [27292:0x38eda20]   310972 ms: Mark-sweep 1400.5 (1488.2) -> 1400.5 (1487.2) MB, 2265.6 / 0.0 ms  (+ 0.0 ms in 0 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2266 ms) last resort
transform[stdout]: [27292:0x38eda20]   313353 ms: Mark-sweep 1400.5 (1487.2) -> 1400.5 (1487.2) MB, 2381.0 / 0.0 ms  last resort
transform[stdout]:
transform[stdout]:
transform[stdout]: <--- JS stacktrace --->
transform[stdout]:
transform[stdout]: ==== JS stack trace =========================================
transform[stdout]:
transform[stdout]: Security context: 0x1dd6f1c1bbd9 <JS Object>
transform[stdout]:     2: SourceMapGenerator_serializeMappings [/code/app-react/rn-code/node_modules/source-map/lib/source-map-generator.js:~291] [pc=0x1cb61604b9da](this=0x4a5839b6119 <a SourceMapGenerator with map 0x3874804e651>)
transform[stdout]:     3: SourceMapGenerator_toJSON [/code/app-react/rn-code/node_modules/source-map/lib/source-map-generator.js:381] [pc=0x1cb6161fcdf2](this=0x4a5839b6119 <a SourceMapGenerator with map...
transform[stdout]:
transform[stderr]: FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
transform[stderr]:  1: node::Abort() [/root/.nvm/versions/node/v8.2.1/bin/node]
transform[stderr]:  2: 0x136849c [/root/.nvm/versions/node/v8.2.1/bin/node]
transform[stderr]:  3: v8::Utils::ReportOOMFailure(char const*, bool) [/root/.nvm/versions/node/v8.2.1/bin/node]
transform[stderr]:  4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/root/.nvm/versions/node/v8.2.1/bin/node]
transform[stderr]:  5:
transform[stderr]: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/root/.nvm/versions/node/v8.2.1/bin/node]
transform[stderr]:  6: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/root/.nvm/versions/node/v8.2.1/bin/node]
transform[stderr]:  7: 0x1cb615f040bd

I have some problem after upgrading from RN 0.44.0 to 0.48.4. Node do not increase memory size with parametr --max_old_space_size, ignoring it

I know you said you increased the memory, but was it using this command below? Issue 5196 refers to a few ways of changing it, some of which seem to be outdated.

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 --bundle-output "ios/main.jsbundle" --assets-dest "ios" --reset-cache