背景

随着项目越来越庞大,webpack开发的时候构建占用的内存也会越来越多,今天跑项目发现报内存泄漏,报错如下

<--- Last few GCs --->

[5089:0x102648000]    11429 ms: Mark-sweep 117.8 (127.9) -> 117.0 (127.9) MB, 68.9 / 0.0 ms  (average mu = 0.247, current mu = 0.238) allocation failure scavenge might not succeed
[5089:0x102648000]    11506 ms: Mark-sweep 117.6 (127.9) -> 117.3 (128.4) MB, 69.9 / 0.0 ms  (average mu = 0.176, current mu = 0.097) allocation failure scavenge might not succeed


<--- JS stacktrace --->

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

    0: ExitFrame [pc: 0x2a65c6c5be3d]
Security context: 0x274a7279e6e1 <JSObject>
    1: stringSlice(aka stringSlice) [0x274ac1b9d419] [buffer.js:594] [bytecode=0x274ac1bd3f69 offset=91](this=0x274a2d3026f1 <undefined>,buf=0x274a2f12d061 <Uint8Array map = 0x274a1f9d1a39>,encoding=0x274a727bd7b9 <String[4]: utf8>,start=0,end=22299)
    2: toString [0x274aaee9df91] [buffer.js:~643] [pc=0x2a65c6c700b1](this=0x274a2f12d061 <Uint8Array map = 0...

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

解决方法

node --max_old_space_size=4096 node_modules/.bin/webpack-dev-server

 

本文为原创,未经授权,禁止任何媒体或个人自媒体转载
商业侵权必究,如需授权请联系[email protected]
标签: webpack React