Linux下Webpack打包内存不足

报错信息

<--- Last few GCs --->
[3715:0x289d6e0]   476979 ms: Mark-sweep 1331.0 (1501.2) -> 1331.0 (1501.7) MB, 1810.0 / 0.0 ms  allocation failure GC in old space requested
[3715:0x289d6e0]   478716 ms: Mark-sweep 1331.0 (1501.7) -> 1330.9 (1456.2) MB, 1736.6 / 0.0 ms  last resort GC in old space requested
[3715:0x289d6e0]   480175 ms: Mark-sweep 1330.9 (1456.2) -> 1330.9 (1456.2) MB, 1459.1 / 0.0 ms  last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x207037a25879 <JSObject>
    2: /* anonymous */ [0x2495e7022d1 <undefined>:~5467] [pc=0x2eff9588dc48](this=0x3a9b4d5c41c9 <JSFunction base54 (sfi = 0x228383a61e71)>,str=0x3cfb753f6e91 <Very long string[7065912]>,delta=1)
    3: /* anonymous */ [0x2495e7022d1 <undefined>:5436] [bytecode=0xb637c861cf1 offset=83](this=0x1f4ff1b82349 <AST_Toplevel map = 0x3ada19217079>,options=0x1c634c40d0a1 <Object map = 0x3d2e4320c31>)
  ...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [node]
 2: 0x8c21ec [node]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [node]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [node]
 5: v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [node]
 6: v8::internal::String::SlowFlatten(v8::internal::Handle<v8::internal::ConsString>, v8::internal::PretenureFlag) [node]
 7: v8::internal::Runtime_StringCharCodeAtRT(int, v8::internal::Object**, v8::internal::Isolate*) [node]
 8: 0x2eff94a042fd

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ant-design-pro@2.1.1 build: `cross-env BUILD_TYPE=prod umi build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the ant-design-pro@2.1.1 build 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-10-17T07_53_02_983Z-debug.log
script returned exit code 1

解决办法

设置nodejs的内存使用限制

# 这里设置为4G,应该够用了
 export NODE_OPTIONS=--max_old_space_size=4096
# 将该变量写入到配置文件中
echo 'export NODE_OPTIONS=--max_old_space_size=4096' >> /etc/profile

注意

这个方法只针对2017年8月发布的Node.js v8.0之后的版本

参考

https://www.npmjs.com/package/increase-memory-limit

你可能感兴趣的:(前端,运维)