FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

今天在用angular 7的build prud的时候出现了下面的错误:

 1: node::Abort() [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 2: 0x8cd14c [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 3: v8::Utils::ReportOOMFailure(char const*, bool) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 4: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 5: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 6: v8::internal::HashTable::NewInternal(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 7: v8::internal::HashTable::New(v8::internal::Isolate*, int, v8::internal::PretenureFlag, v8::internal::MinimumCapacity) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 8: v8::internal::HashTable::EnsureCapacity(v8::internal::Handle, int, v8::internal::PretenureFlag) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
 9: v8::internal::Dictionary::Add(v8::internal::Handle, unsigned int, v8::internal::Handle, v8::internal::PropertyDetails, int*) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
10: 0xd7fd76 [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
11: v8::internal::JSObject::AddDataElement(v8::internal::Handle, unsigned int, v8::internal::Handle, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
12: v8::internal::Object::AddDataProperty(v8::internal::LookupIterator*, v8::internal::Handle, v8::internal::PropertyAttributes, v8::internal::Object::ShouldThrow, v8::internal::Object::StoreFromKeyed) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
13: v8::internal::Object::SetProperty(v8::internal::LookupIterator*, v8::internal::Handle, v8::internal::LanguageMode, v8::internal::Object::StoreFromKeyed) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
14: v8::internal::Runtime_SetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
15: 0x1c9837d042fd
Aborted

heap out of memory

解决方法

在你的命令前面加上:

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

就可以了,这是为了提升node的内存上限。

参考文献

[1].Node - 'JavaScript heap out of memory'. https://developers.de/2018/06/29/node-fix-javascript-heap-out-of-memory/

[2].FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory error. https://stackoverflow.com/questions/50621043/fatal-error-call-and-retry-last-allocation-failed-javascript-heap-out-of-memo

你可能感兴趣的:(node.js,Angular)