致命错误:使用任何“npm”命令时 JavaScript 堆内存不足
Posted
技术标签:
【中文标题】致命错误:使用任何“npm”命令时 JavaScript 堆内存不足【英文标题】:FATAL ERROR: JavaScript heap out of memory when using any "npm" command 【发布时间】:2019-09-23 18:43:54 【问题描述】:尝试运行任何 npm 命令时出现错误(致命错误:MarkCompactCollector:半空间复制,旧代分配失败 - javascript 堆内存不足)。即使运行“npm -v”也会发生错误。
也经历了线程-(npm install - javascript heap out of memory),但这对我的情况没有帮助。
胎儿错误
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed
-
JavaScript heap out of memory
1: 000000013F56F04A
v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
2: 000000013F54A0C6 node::MakeCallback+4518
3: 000000013F54AA30 node_module_register+2032
4: 000000013F7D20EE v8::internal::FatalProcessOutOfMemory+846
5: 000000013F7D201F v8::internal::FatalProcessOutOfMemory+639
6: 000000013FCF2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
7: 000000013FCE9C46 v8::internal::ScavengeJob::operator=+24310
8: 000000013FCE829C v8::internal::ScavengeJob::operator=+17740
9: 000000013FCEE1B7 v8::internal::Heap::CreateFillerObjectAt+1175
10: 000000013FB7C5B3
v8::internal::interpreter::Interpreter::GetDispatchCounters
Object+78451
11: 000000013F4D1132
v8::internal::StackGuard::ArchiveSpacePerThread+52082
12: 000000013F4D17F3
v8::internal::StackGuard::ArchiveSpacePerThread+53811
13: 000000013F5B1474 uv_dlerror+2436
14: 000000013F5B21D8 uv_run+232
15: 000000013F55128E node::NewContext+1390
16: 000000013F55189B node::NewIsolate+603
17: 000000013F551D07 node::Start+839
18: 000000013F40935C node::MultiIsolatePlatform::MultiIsolatePlatform+604
19: 000000013FFAA93C
v8::internal::compiler::OperationTyper::ToBoolean+134796
20: 0000000076D3555D BaseThreadInitThunk+13
21: 0000000076F9385D RtlUserThreadStart+29
<--- Last few GCs --->
[13304:0000000000182610] 135335 ms: Mark-sweep 1396.6 (1426.7) -> 1396.6 (1424
.7) MB, 2368.0 / 0.0 ms (+ 0.0 ms in 1 steps since start of marking, biggest st
ep 0.0 ms, walltime since start of marking 2368 ms) (average mu = 0.099, current
mu = 0.035) fi[13304:0000000000182610] 135404 ms: Scavenge 1397.6 (1424.7) ->
1397.1 (1428.2) MB, 3.7 / 0.0 ms (average mu = 0.099, current mu = 0.035) allo
cation failure
<--- JS stacktrace --->
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed -
JavaS
cript heap out of memory
1: 000000013FD7F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
2: 000000013FD5A0C6 node::MakeCallback+4518
3: 000000013FD5AA30 node_module_register+2032
4: 000000013FFE20EE v8::internal::FatalProcessOutOfMemory+846
5: 000000013FFE201F v8::internal::FatalProcessOutOfMemory+639
6: 0000000140502BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
7: 00000001404F9C46 v8::internal::ScavengeJob::operator=+24310
8: 00000001404F829C v8::internal::ScavengeJob::operator=+17740
9: 00000001404FE1B7 v8::internal::Heap::CreateFillerObjectAt+1175
10: 000000014038C5B3
v8::internal::interpreter::Interpreter::GetDispatchCounters
Object+78451
11: 000000013FCE1132 v8::internal::StackGuard::ArchiveSpacePerThread+52082
12: 000000013FCE17F3 v8::internal::StackGuard::ArchiveSpacePerThread+53811
13: 000000013FDC1474 uv_dlerror+2436
14: 000000013FDC21D8 uv_run+232
15: 000000013FD6128E node::NewContext+1390
16: 000000013FD6189B node::NewIsolate+603
17: 000000013FD61D07 node::Start+839
18: 000000013FC1935C node::MultiIsolatePlatform::MultiIsolatePlatform+604
19: 00000001407BA93C
v8::internal::compiler::OperationTyper::ToBoolean+134796
20: 0000000076D3555D BaseThreadInitThunk+13
21: 0000000076F9385D RtlUserThreadStart+29
【问题讨论】:
另见:Node.js heap out of memory 【参考方案1】:我遇到了完全相同的问题,并且花了很长时间才知道发生了什么。如果即使npm -v
对您失败,那么您的问题不是由内存不足引起的,而是.npmrc
文件中的设置不正确。在我的例子中,我从旧机器上复制了.npmrc
,并重新定义了prefix
和cache
设置:
prefix=D:\npm-projects\npm
cache=D:\npm-projects\npm-cache
在我的新机器上,我只有C:\
驱动器,因此npm
正在疯狂地尝试处理这些设置。一旦我将所有内容更改为指向C:\npm-projects\xxxx
,问题就消失了。
【讨论】:
【参考方案2】:您需要提高节点允许的内存量。
您可以通过以下方式在全局范围内执行此操作:
-
打开
cmd
窗口
运行setx NODE_OPTIONS --max_old_space_size=10240
关闭所有 cmd/代码编辑器
重新打开 cmd 并再次运行您的节点命令(npm 等)
【讨论】:
这在 Mac 上对我不起作用。setx
找不到命令。 FWIW。
这不是解决方案,而是解决方法。在给节点 10GB 之前! RAM,理解它为什么需要这么多是有道理的。我来这里是为了找到有关如何解决内存问题的步骤,但发现了这个。呃……以上是关于致命错误:使用任何“npm”命令时 JavaScript 堆内存不足的主要内容,如果未能解决你的问题,请参考以下文章
尝试 npm install web3 时出现致命错误 LNK1181
每当我尝试在 VS Code 中运行任何与 npm 相关的命令时,都会出现路径错误:[找不到模块]