npm运行构建不会消耗centos上的交换内存,并且错误会堆出内存

ygya80vv  于 10个月前  发布在  其他
关注(0)|答案(1)|浏览(82)

我运行npm run build给予内存问题如下:

# npm run build

> fuse@9.0.0 build
> ng build

93% after chunk asset optimization SourceMapDevToolPlugin main-es2015.js generate SourceMap
<--- Last few GCs --->

[6311:0x50b4290]   182740 ms: Mark-sweep (reduce) 904.3 (936.0) -> 902.4 (935.6) MB, 1689.5 / 0.1 ms  (average mu = 0.190, current mu = 0.245) allocation failure scavenge might not succeed
[6311:0x50b4290]   182856 ms: Scavenge (reduce) 903.4 (935.6) -> 902.5 (935.6) MB, 2.5 / 0.0 ms  (average mu = 0.190, current mu = 0.245) allocation failure
[6311:0x50b4290]   182906 ms: Scavenge (reduce) 903.5 (935.6) -> 902.5 (935.6) MB, 4.1 / 0.0 ms  (average mu = 0.190, current mu = 0.245) allocation failure

<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0xb02960 node::Abort() [ng build]
 2: 0xa18149 node::FatalError(char const*, char const*) [ng build]
 3: 0xcdd22e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build]
 4: 0xcdd5a7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build]
 5: 0xe94c15  [ng build]
 6: 0xe956f6  [ng build]
 7: 0xea3c1e  [ng build]
 8: 0xea4660 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build]
 9: 0xea75de v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [ng build]
10: 0xe68b1a v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [ng build]
11: 0x11e1886 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [ng build]
12: 0x15d54f9  [ng build]
/tmp/build-e8d9a101.sh: line 1:  6311 Aborted                 ng build

字符串
我有2 GB的真实的内存和4 GB的SWAP内存。
我做了实时监控,发现npm run build不消耗任何swap内存。
我怎样才能使npm run build利用交换内存,这样我就可以克服这个内存问题。
下面是npm命令运行时的实时交换内存统计数据,正如你所看到的,它只占用实时内存,忽略swap内存:
npm build run之前的内存:

[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837         328        1133         101         375        1233
Swap:          4095          31        4064


内存运行后的权利,当它崩溃:

[root@vultr ~]# sudo swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file   4G 29.9M   -2
[root@vultr ~]# sudo swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file   4G 29.9M   -2
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837        1518          73         101         245          72
Swap:          4095          29        4066
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837        1516          75         101         245          74
Swap:          4095          29        4066
[root@vultr ~]# sudo swapon --show
NAME      TYPE SIZE  USED PRIO
/swapfile file   4G 29.9M   -2
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837        1520          70         101         245          70
Swap:          4095          29        4066
[root@vultr ~]# free -m
              total        used        free      shared  buff/cache   available
Mem:           1837         450        1120         101         267        1130
Swap:          4095          31        4064

huwehgph

huwehgph1#

export NODE_OPTIONS=--max-old-space-size=4096帮助解决了这个问题。现在使用交换内存。

相关问题