はじめに
npm search
時に JavaScript heap out of memory
が発生して少し嵌ったので、備忘のため残しておく。
環境
- OS: OS X 10.11.1
- Homebrew: 1.0.7
- nodejs: 6.7.0
嵌ったエラー
以下にある FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
エラー。
おそらく JS
の Heap Memory
の閾値に引っかかっているのだろう。
$ npm search babel-cli
npm ERR! Darwin 15.0.0
npm ERR! argv "/usr/local/Cellar/node/6.7.0/bin/node" "/usr/local/bin/npm" "search" "babel"
npm ERR! node v6.7.0
npm ERR! npm v3.10.7
npm ERR! Cannot read property '_updated' of undefined
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm WARN Building the local index for the first time, please be patient
<--- Last few GCs --->
96862 ms: Mark-sweep 1017.7 (1334.2) -> 991.3 (1314.1) MB, 889.9 / 0.0 ms [allocation failure] [GC in old space requested].
97819 ms: Mark-sweep 991.3 (1314.1) -> 991.2 (1318.1) MB, 957.7 / 0.0 ms [allocation failure] [GC in old space requested].
98807 ms: Mark-sweep 991.2 (1318.1) -> 991.1 (1278.1) MB, 987.9 / 0.0 ms [last resort gc].
99792 ms: Mark-sweep 991.1 (1278.1) -> 991.1 (1271.1) MB, 984.2 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x30bede1cfb51 <JS Object>
1: fromString(aka fromString) [buffer.js:195] [pc=0x391d7a84a870] (this=0x30bede104381 <undefined>,string=0x2a93cd544901 <Very long string[206551764]>,encoding=0x30bede1dd329 <String[4]: utf8>)
2: from [buffer.js:95] [pc=0x391d7a83f062] (this=0x108f705e93a1 <JS Function Buffer (SharedFunctionInfo 0xb35d5f6389)>,value=0x2a93cd544901 <Very long string[206551764]>,encodingOrOffset=0x30bede...
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::Utils::ReportApiFailure(char const*, char const*) [/usr/local/bin/node]
4: v8::Utils::ApiCheck(bool, char const*, char const*) [/usr/local/bin/node]
5: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
6: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
7: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [/usr/local/bin/node]
8: v8::String::WriteUtf8(char*, int, int*, int) const [/usr/local/bin/node]
9: node::StringBytes::Write(v8::Isolate*, char*, unsigned long, v8::Local<v8::Value>, node::encoding, int*) [/usr/local/bin/node]
10: node::Buffer::New(v8::Isolate*, v8::Local<v8::String>, node::encoding) [/usr/local/bin/node]
11: node::Buffer::CreateFromString(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
12: v8::internal::FunctionCallbackArguments::Call(void (*)(v8::FunctionCallbackInfo<v8::Value> const&)) [/usr/local/bin/node]
13: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)1>) [/usr/local/bin/node]
14: v8::internal::Builtin_Impl_HandleApiCall(v8::internal::(anonymous namespace)::BuiltinArguments<(v8::internal::BuiltinExtraArguments)1>, v8::internal::Isolate*) [/usr/local/bin/node]
15: v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
16: 0x391d7a4092a7
Abort trap: 6
どうも old-space
が1GB程度で閾値に達してしまいエラーになっているように見える。
対応手順
-max-old-space-size
を大きくして以下のように再実行したら成功した。
$ node --max-old-space-size=8192 $(which npm) search babel-cli
NAME DESCRIPTION AUTHOR DATE VERSION KEYWORDS
babel-cli Babel command line. =amasad =hzoo =jmm… 2016-10-04 6.16.0
babel-cli-justwatch Babel command line. =lxe 2016-04-30 6.7.7
better-babel-cli A better babel command-line utility =ksherlock 2016-08-30 1.2.1 babel
grunt-babel-cli Grunt CLI wrapper for writing Gruntfiles in es6 syntax. =mlegenhausen 2015-07-30 1.0.1 grunt babel es6 cli gruntfile config configuration
reactifying ES6 React Babel hello world =khurramijazm 2015-12-17 1.0.0 babel-cli reactjs
redux-composer ```sh npm install babel-cli -g =gajus 2016-01-30 0.0.0
start-babel-cli Babel CLI for Start =deepsweet 2016-09-22 3.0.0 start start-cli
$
しかしnpmコマンドって結構なメモリ使うんだね
おしまい。