【打包报错】FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out

前端工程打包时,出现了
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
问题

[11:38:29] <--- JS stacktrace --->
[11:38:29] 
[11:38:29] FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
[11:38:29]  1: 0xb02d90 node::Abort() [node]
[11:38:29]  2: 0xa18123 node::FatalError(char const*, char const*) [node]
[11:38:29]  3: 0xceb85e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
[11:38:29]  4: 0xcebbd7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
[11:38:29]  5: 0xeb55b5  [node]
[11:38:29]  6: 0xeb60a4  [node]
[11:38:29]  7: 0xec4517 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
[11:38:29]  8: 0xec78cc v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
[11:38:29]  9: 0xe8a1ec v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
[11:38:29] 10: 0x11f70a6 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
[11:38:29] 11: 0x15cdf39  [node]
[11:38:39] /root/workspace/user_command.sh:行 37:  1281 已放弃               (核心已转储) npm run build:dev

可以尝试修改打包命令,增加一行参数来处理:

--max_old_space_size=4096

如:vite的打包,可以改为:

# 修改前:
vite build --mode production
# 修改后
node --max_old_space_size=4096 node_modules/vite/bin/vite.js build --mode production

猜你喜欢

转载自blog.csdn.net/weixin_40240616/article/details/140843975