今天在用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<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::NewInternal(v8::internal::Isolate*, int, v8::internal::PretenureFlag) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
7: v8::internal::HashTable<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::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<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::EnsureCapacity(v8::internal::Handle<v8::internal::SeededNumberDictionary>, int, v8::internal::PretenureFlag) [ng build --prod --build-optimizer --base-href /admin --deploy-url /admin/]
9: v8::internal::Dictionary<v8::internal::SeededNumberDictionary, v8::internal::SeededNumberDictionaryShape>::Add(v8::internal::Handle<v8::internal::SeededNumberDictionary>, unsigned int, v8::internal::Handle<v8::internal::Object>, 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<v8::internal::JSObject>, unsigned int, v8::internal::Handle<v8::internal::Object>, 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::Object>, 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::Object>, 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