1、问题描述

发布运营后台 WEB 的时候报 JavaScript heap out of memory

开始编译 shop-operate-admin...
npm WARN deprecated npmlog@5.0.1: This package is no longer supported.
npm WARN deprecated rimraf@3.0.2: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated are-we-there-yet@2.0.0: This package is no longer supported.
npm WARN deprecated gauge@3.0.2: This package is no longer supported.

up to date, audited 2099 packages in 22s

150 packages are looking for funding
  run `npm fund` for details

165 vulnerabilities (7 low, 108 moderate, 29 high, 21 critical)

To address issues that do not require attention, run:
  npm audit fix

To address all issues possible (including breaking changes), run:
  npm audit fix --force

Some issues need review, and may require choosing
a different dependency.

Run `npm audit` for details.

> vue-element-admin@4.3.1 yxmr-build
> vue-cli-service build --mode yxmr


-  Building for yxmr...

<--- Last few GCs --->

[151839:0x525710]    75042 ms: Scavenge 1436.2 (1870.9) -> 1434.6 (1886.2) MB, 17.8 / 0.0 ms  (average mu = 0.858, current mu = 0.705) allocation failure 
[151839:0x525710]    76077 ms: Mark-sweep 1694.2 (2131.8) -> 1679.2 (2133.1) MB, 799.5 / 0.1 ms  (+ 100.9 ms in 788 steps since start of marking, biggest step 0.9 ms, walltime since start of marking 1319 ms) (average mu = 0.788, current mu = 0.706) alloca

<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0x7f35c76edd78 node::Abort() [/lib64/libnode.so.93]
 2: 0x7f35c75dba73  [/lib64/libnode.so.93]
 3: 0x7f35c88eba20 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/lib64/libnode.so.93]
 4: 0x7f35c88ebde7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/lib64/libnode.so.93]
 5: 0x7f35c8aab7e5  [/lib64/libnode.so.93]
 6: 0x7f35c8ac1654  [/lib64/libnode.so.93]
 7: 0x7f35c8ac3749 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/lib64/libnode.so.93]
 8: 0x7f35c8ac37d7 v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/lib64/libnode.so.93]
 9: 0x7f35c8a83cb0 v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/lib64/libnode.so.93]
10: 0x7f35c8a7e6ec v8::internal::FactoryBase::AllocateRawArray(int, v8::internal::AllocationType) [/lib64/libnode.so.93]
11: 0x7f35c8a7e7c4 v8::internal::FactoryBase::NewFixedArrayWithFiller(v8::internal::Handle, int, v8::internal::Handle, v8::internal::AllocationType) [/lib64/libnode.so.93]
12: 0x7f35c8e7d7b5 v8::internal::FixedArrayBuilder::EnsureCapacity(v8::internal::Isolate*, int) [/lib64/libnode.so.93]
13: 0x7f35c8e30b03 v8::internal::Runtime_RegExpExecMultiple(int, unsigned long*, v8::internal::Isolate*) [/lib64/libnode.so.93]
14: 0x7f35c87e6d19  [/lib64/libnode.so.93]
/home/yhsp/ci/sh/web/functions.sh: 行 4: 151828 已放弃               (吐核)npm run yxmr-build

2、解决方案

vim  /home/yhsp/ci/sh/web/functions.sh 在文件头添加 export NODE_OPTIONS=–max_old_space_size=4096,给 node 环境4G 内存。