1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

react-native bundle で FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

Last updated at Posted at 2019-01-29

React Nativeアプリのビルド環境をdocker上に構築しているのですが、あるタイミングで react-native bundle コマンドが以下のようなエラーを出力し失敗するようになってしまいました。

> react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Loading dependency graph, done.
Loading dependency graph...
<--- Last few GCs --->

[24:0x3def1e0]   805808 ms: Mark-sweep 1323.4 (1536.9) -> 1323.3 (1537.4) MB, 2489.5 / 0.0 ms  allocation failure GC in old space requested
[24:0x3def1e0]   808226 ms: Mark-sweep 1323.3 (1537.4) -> 1323.2 (1489.4) MB, 2413.2 / 0.0 ms  last resort GC in old space requested
[24:0x3def1e0]   810702 ms: Mark-sweep 1323.2 (1489.4) -> 1323.2 (1484.4) MB, 2474.2 / 0.0 ms  last resort GC in old space requested


<--- JS stacktrace --->

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

Security context: 0x2e41a2725879 <JSObject>
    1: _append [/app/node_modules/@babel/generator/lib/buffer.js:~112] [pc=0x3a9aabf22649](this=0x3f72c6539ee1 <Buffer map = 0x247c946822b1>,str=0x2e41a277c0c9 <String[1]:  >,line=6105,column=26,identifierName=0x2e3c0c782201 <null>,filename=0x2e3c0c782201 <null>,force=0x2e3c0c7823e1 <false>)
    2: token [/app/node_modules/@babel/generator/lib/printer.js:~126] [pc=0x3a9aabf2fe00](this=0x3f72c653...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x8cbf4c [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewUninitializedFixedArray(int) [node]
 6: 0xd7fc13 [node]
 7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 8: 0x3a9aab0842fd
Aborted
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! react_project@0.0.1 android-linux: `react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res`
npm ERR! Exit status 134
npm ERR! 
npm ERR! Failed at the react_project@0.0.1 android-linux script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2019-01-28T07_35_33_700Z-debug.log

以下の2つを実施することで解決しました。

  • dockerコンテナへの割当メモリを増やす
docker-compose.yml
version: '3'
services:
  deploy:
    build: .
    volumes:
      - .:/app
      - data-gradle:/root/.gradle
      - data-nodemodules:/app/node_modules
    working_dir: /app
     # 追記
    shm_size: 4GB 
volumes:
  data-gradle:
  data-nodemodules:
  • react-native bundle コマンド実行時、nodeのオプション--expose-gc --max_old_space_sizeを指定する
    コマンド全体はこのようになります。
node --expose-gc --max_old_space_size=2048 $(npm bin)/react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

追記

assembleDebug|Release するときは、build.gradleからも同じオプションを設定する必要があります。
nodeExecutableAndArgs という設定値でデフォルトの node コマンドにオプションを追加することができます。

app/build.gradle
project.ext.react = [
        bundleAssetName: "index.android.bundle",
        entryFile      : "index.js",
        bundleInDebug  : true,
        bundleInRelease: true,
        root           : "../../",
        nodeExecutableAndArgs: ["node","--expose-gc","--max_old_space_size=2048"],  //  追記
]
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?