首页 > 前端技术 > JavaScript heap out of memory in angular – 堆内存溢出
2021
03-18

JavaScript heap out of memory in angular – 堆内存溢出

<— Last few GCs —>

 

[54681:0x10264b000]    73532 ms: Mark-sweep 1366.9 (1447.9) -> 1356.6 (1450.9) MB, 991.1 / 0.0 ms  (average mu = 0.131, current mu = 0.067) allocation failure scavenge might not succeed

[54681:0x10264b000]    74552 ms: Mark-sweep 1369.3 (1450.9) -> 1359.2 (1453.4) MB, 960.6 / 0.0 ms  (average mu = 0.096, current mu = 0.059) allocation failure scavenge might not succeed

<— JS stacktrace —>

 

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

 

0: ExitFrame [pc: 0x17ef1325be3d]

1: StubFrame [pc: 0x17ef132134b0]

Security context: 0x25899cf9e6e1 <JSObject>

2: SourceMapConsumer_parseMappings [0x25894bfd9529] [……node_modules/webpack-sources/node_modules/source-map/lib/source-map-consumer.js:~468] [pc=0x17ef14d3e41c](this=0x2589f3f29309 <BasicSourceMapConsumer map = 0x2589b2592e79>,aStr=0x258907ddd4c1 <Very long string[13324]>,aSou…

 

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed – JavaScript heap out of memory

1: 0x10003b125 node::Abort() [……/.nvm/versions/node/v10.15.0/bin/node]

2: 0x10003b32f node::OnFatalError(char const*, char const*) [……/.nvm/versions/node/v10.15.0/bin/node]

3: 0x1001a8e85 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [……/.nvm/versions/node/v10.15.0/bin/node]

4: 0x1005742a2 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [……/.nvm/versions/node/v10.15.0/bin/node]

5: 0x100576d75 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [……/.nvm/versions/node/v10.15.0/bin/node]

6: 0x100572c1f v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [……/.nvm/versions/node/v10.15.0/bin/node]

7: 0x100570df4 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [……/.nvm/versions/node/v10.15.0/bin/node]

8: 0x10057d68c v8::internal::Heap::AllocateRawWithLigthRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [……/.nvm/versions/node/v10.15.0/bin/node]

9: 0x10057d70f v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [……/.nvm/versions/node/v10.15.0/bin/node]

10: 0x10054d054 v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [……/.nvm/versions/node/v10.15.0/bin/node]

11: 0x1007d4f24 v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [……/.nvm/versions/node/v10.15.0/bin/node]

12: 0x17ef1325be3d

13: 0x17ef132134b0

14: 0x17ef14d3e41c

15: 0x17ef132118d5

npm start 时报堆内存溢出,解决方案一

try running the build with this

node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve 

or other way is to add this to the package.json

"build-serve": "node --max_old_space_size=8048 ./node_modules/@angular/cli/bin/ng serve" 

where 8048 is the max heap size.

 

解决方案二: node升级至12以上

If you’re on older version of NodeJS, then upgrading NodeJS to v12 helps solving this problem.

NodeJS v12 has different heap management strategy, see more info here.

最后编辑:
作者:管理员
这个作者貌似有点懒,什么都没有留下。