构建vue大项目报错:Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memo
Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
·
环境
Windows 10
vscode
过程
今天在构建一个Vue大项目时(我使用的是yarn run build
命令构建项目),遇到一个内存不足的报错,如下:
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF73231012F node_api_throw_syntax_error+175407
2: 00007FF732295AF6 SSL_get_quiet_shutdown+63110
3: 00007FF732296EB2 SSL_get_quiet_shutdown+68162
4: 00007FF732D2FF24 v8::Isolate::ReportExternalAllocationLimitReached+116
5: 00007FF732D1B282 v8::Isolate::Exit+674
6: 00007FF732B9D0DC v8::internal::EmbedderStackStateScope::ExplicitScopeForTesting+124
7: 00007FF732BAA3BD v8::internal::Heap::PublishPendingAllocations+1117
8: 00007FF732BA7447 v8::internal::Heap::PageFlagsAreConsistent+3367
9: 00007FF732B99B77 v8::internal::Heap::CollectGarbage+2039
10: 00007FF732BB0533 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath+2099
11: 00007FF732BB0DDD v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath+93
12: 00007FF732BC0613 v8::internal::Factory::NewFillerObject+851
13: 00007FF7328B1BC5 v8::internal::DateCache::Weekday+1349
14: 00007FF732DCD5C1 v8::internal::SetupIsolateDelegate::SetupHeap+558193
15: 00007FF732DA0833 v8::internal::SetupIsolateDelegate::SetupHeap+374499
16: 00007FF732D4E990 v8::internal::SetupIsolateDelegate::SetupHeap+38976
17: 00007FF6B4B75385
error Command failed with exit code 134.
解决方法
1、打开【环境变量设置】窗口,位置在:控制面板 -> 系统和安全 -> 系统 -> 高级系统设置 -> 高级 -> 环境变量
2、新建一个名为NODE_OPTIONS
、值为--max-old-space-size=xxxx
的变量,xxxx是内存MB大小,例如4096就是4GB:
3、点击 确定 退出【环境变量设置】窗口
4、打开一个新的 PowerShell 命令窗口,执行以下命令查看环境变量是否生效:
node -e 'console.log(v8.getHeapStatistics().heap_size_limit/(1024*1024))'
显示为4144,证明已经生效
问:为什么环境变量里设置的值是4096,但却显示4144,比设置的值要大一些?
答:暂时不清楚,后面再研究,或者知道原因的小伙伴可以在评论区留言:)
5、重新构建项目,成功!
其它问题
1、如果设置环境变量后,构建还是失败,可以继续调大变量的值,4GB不够就加大到8GB,如此类推。注意修改完变量后,需要打开新的 PowerShell 窗口才会生效。
2、尽量不要使用vscode自带的终端窗口构建项目,因为设置了环境变量后,在vscode的终端窗口里是不会生效的,除非重启系统。解决方法可以参阅:windows 修改环境变量后在 vscode 的终端不生效的解决方法
更多推荐
已为社区贡献1条内容
所有评论(0)