LoginSignup
1

More than 3 years have passed since last update.

Reactでstorybook起動時にJavaScript heap out of memoryが出たけど解決した話

Last updated at Posted at 2019-11-19

起きたこと

storybook-cliでstorybook起動すると、以下のエラーが出た。

<--- Last few GCs --->

[88509:0x10264e000]  3090375 ms: Mark-sweep 1400.2 (1456.1) -> 1392.7 (1438.6) MB, 2595.6 / 0.0 ms  (+ 0.1 ms in 211 steps since start of marking, biggest step 0.0 ms, walltime since start of marking 2619 ms) (average mu = 0.110, current mu = 0.009) alloc[88509:0x10264e000]  3091708 ms: Mark-sweep 1399.9 (1438.6) -> 1398.6 (1441.6) MB, 1066.4 / 0.0 ms  (+ 237.0 ms in 115 steps since start of marking, biggest step 8.9 ms, walltime since start of marking 1331 ms) (average mu = 0.080, current mu = 0.023) all

<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x2c4a8b5be3d]
Security context: 0x3b6807a1e6e9 <JSObject>
    1: getMembers(aka getMembers) [0x3b68e8af6ee1] [/Users/xxx/src/github.com/xxx/xxxx/node_modules/react-docgen/dist/utils/getMembers.js:~43] [pc=0x2c4ab62e217](this=0x3b680b0826f1 <undefined>,/* anonymous */=0x3b68a3874f79 <NodePath map = 0x3b68dca0b9f1>,/* anonymous */=0x3b680b0828c9 <true>)
    2: getPropType(aka getPropType) [0x3b68e8...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x10003c597 node::Abort() [/Users/xxx/.nvm/versions/node/v10.15.3/bin/node]
 2: 0x10003c7a1 node::OnFatalError(char const*, char const*) 
...

メモリが足りないのかと思い、 --max-old-space-size オプションで8GBのメモリを使うよう設定しても、8GB使い切って上記のエラーが出た。

解決方法

PropTypes.arrayOf()

のように PropTypes.arrayOfを引数なしで使っている箇所があった。引数指定すれば上記エラーが出なくなった

// 修正後
PropTypes.arrayOf(PropTypes.any)

関係ありそうなパッケージのバージョン

"@storybook/cli": "^5.2.6",
"prop-types": "^15.7.2",
"eslint-plugin-react": "^7.12.4",
"react": "^16.8.6",

詳しい原因について

未調査

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