nodejs多版本控制工具-nvm、npm命令丢失、内存溢出等问题

本文介绍了如何使用nvm管理Node.js的安装、卸载和版本切换,解决npm命令缺失和Node.js内存溢出的问题。包括设置npm镜像、增加内存限制以及处理vue-cli服务的命令配置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装node

1.nvm下载地址
https://github.com/coreybutler/nvm-windows/releases

常用命令

1.安装

nvm install 12.14.1

2.卸载

nvm uninstall 12.14.1

3.切换

nvm use 12.14.1

4.查看已安装版本

nvm list

npm命令不存在

1.卸载缺失npm的node版本

nvm uninstall 12.14.1

2.切换镜像地址

nvm npm_mirror https://npm.taobao.org/mirrors/npm/

3.重装指定版本的node

nvm install 12.14.1

注意:如果用的是 vscode 集成的终端,可能 npm 命令依旧不存在,这时候可以从 cmd 启动终端 npm -v 检查。检查安装成功后,重启电脑就可以了。

在此系统上禁止运行脚本

两种解决方案
1.右键,以管理员身份运行。
2.命令行里执行一下代码更改策略

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

原因:这个错误是由于 PowerShell 的执行策略限制导致的。某些系统默认情况下PowerShell 禁止运行脚本。

node内存溢出

1.安装 increase-memory-limitcross-env

npm install -g increase-memory-limit cross-env

2.配置 package.json 里的scripts追加上一个命令配置

"scripts": {
	"fix-memory-limit": "cross-env LIMIT=8048 increase-memory-limit"
}

3.执行新增的命令进行扩容

npm run fix-memory-limit

4.执行编译

npm run dev

node --max-old-space-size=4096不是内部或外部命令

1.找到项目依赖安装目录 node_modules/bin/vue-cli-service.cmd
2.在vue-cli-service.cmd里把【“%_prog%”】外的双引号去掉即可

%_prog%  "%dp0%\..\@vue\cli-service\bin\vue-cli-service.js" %*

在这里插入图片描述

PS D:\zhWork\202501gsykj\control_map> npm run serve > app@0.1.0 serve D:\zhWork\202501gsykj\control_map > vue-cli-service serve Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme INFO Starting development server... [24%] building (3/382 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\public\UEditor\ueditor.all.js as[24%] building (26/427 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\node_modules\element-ui\lib\elem[38%] building (480/745 modules) <--- Last few GCs ---> [16284:00000158F9A7C8B0] 55177 ms: Mark-sweep (reduce) 4090.3 (4104.7) -> 4089.8 (4105.2) MB, 611.9 / 0.0 ms (average mu = 0.121, current mu = 0.008) allocation failure scavenge might not succeed [16284:00000158F9A7C8B0] 56324 ms: Mark-sweep (reduce) 4090.8 (4102.2) -> 4090.3 (4103.7) MB, 1141.7 / 0.0 ms (average mu = 0.048, current mu = 0.004) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 00007FF62825412F napi_wrap+133311 2: 00007FF6281EDD06 SSL_get_quiet_shutdown+63062 3: 00007FF6281EEB9D node::OnFatalError+301 4: 00007FF628AD19CE v8::Isolate::ReportExternalAllocationLimitReached+94 5: 00007FF628AB67BD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62895FFCC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516 7: 00007FF62894AA4B v8::internal::NativeContextInferrer::Infer+59739 8: 00007FF62892FD1F v8::internal::MarkingWorklists::SwitchToContextSlow+56975 9: 00007FF628943A0B v8::internal::NativeContextInferrer::Infer+31003 10: 00007FF62893AAED v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6285 11: 00007FF628942C5E v8::internal::NativeContextInferrer::Infer+27502 12: 00007FF628946CAB v8::internal::NativeContextInferrer::Infer+43963 13: 00007FF6289506A2 v8::internal::ItemParallelJob::Task::RunInternal+18 14: 00007FF628950631 v8::internal::ItemParallelJob::Run+641 15: 00007FF628923C93 v8::internal::MarkingWorklists::SwitchToContextSlow+7683 16: 00007FF62893AF9C v8::internal::MarkCompactCollector::EnsureSweepingCompleted+7484 17: 00007FF6289397D4 v8::internal::MarkCompactCollector::EnsureSweepingCompleted+1396 18: 00007FF628937348 v8::internal::MarkingWorklists::SwitchToContextSlow+87224 19: 00007FF628965DB1 v8::internal::Heap::LeftTrimFixedArray+929 20: 00007FF628967EA5 v8::internal::Heap::PageFlagsAreConsistent+789 21: 00007FF62895D0C1 v8::internal::Heap::CollectGarbage+2049 22: 00007FF62895B2C5 v8::internal::Heap::AllocateExternalBackingStore+1349 23: 00007FF628975155 v8::internal::GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact+1029 24: 00007FF6289755A5 v8::internal::Factory::AllocateRaw+37 25: 00007FF62898AC9E v8::internal::FactoryBase<v8::internal::Factory>::NewStruct+94 26: 00007FF628983A95 v8::internal::Factory::NewStackTraceFrame+53 27: 00007FF6289AD0E2 v8::internal::Isolate::CaptureSimpleStackTrace+2354 28: 00007FF6289AC971 v8::internal::Isolate::CaptureSimpleStackTrace+449 29: 00007FF6289AC0BD v8::internal::Isolate::CaptureAndSetSimpleStackTrace+45 30: 00007FF6289A28A0 v8::internal::MessageLocation::MessageLocation+3664 31: 00007FF6289A63BC v8::internal::MessageFormatter::Format+13100 32: 00007FF62897ADB6 v8::internal::Factory::NewError+134 33: 00007FF628984AF2 v8::internal::Factory::NewTypeError+162 34: 00007FF6289A6561 v8::internal::MessageHandler::MakeMessageObject+337 35: 00007FF6286ABF7C v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+9596 36: 00007FF628B5CDFD v8::internal::SetupIsolateDelegate::SetupHeap+474253 37: 00007FF628AED1C9 v8::internal::SetupIsolateDelegate::SetupHeap+16473 38: 00007FF628AF2FC2 v8::internal::SetupIsolateDelegate::SetupHeap+40530 39: 000002B535527E30 npm ERR! code ELIFECYCLE npm ERR! errno 134 npm ERR! app@0.1.0 serve: `vue-cli-service serve` npm ERR! Exit status 134 npm ERR! npm ERR! Failed at the app@0.1.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! D:\softwareInstall\nvmInstall\nodejs\node_cache\_logs\2025-07-19T14_57_30_569Z-debug.log
最新发布
07-20
PS D:\zhWork\202501gsykj\website-kjcg> npm run dev > results-manage@0.1.0 dev D:\zhWork\202501gsykj\website-kjcg > vue-cli-service serve Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme INFO Starting development server... [24%] building (3/7 modules) [24%] building (5/151 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\website-kjcg\node_modules\element-ui\lib\element-ui.common.js as it exceeds the[51%] building (807/2570 modules) <--- Last few GCs ---> [16848:000001C56D82D290] 63788 ms: Mark-sweep (reduce) 4087.5 (4101.6) -> 4087.0 (4103.1) MB, 629.4 / 0.0 ms (average mu = 0.204, current mu = 0.008) allocation failure scavenge might not succeed [16848:000001C56D82D290] 64421 ms: Mark-sweep (reduce) 4088.0 (4102.1) -> 4087.5 (4103.6) MB, 627.9 / 0.0 ms (average mu = 0.115, current mu = 0.008) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 00007FF62825412F napi_wrap+133311 2: 00007FF6281EDD06 SSL_get_quiet_shutdown+63062 3: 00007FF6281EEB9D node::OnFatalError+301 4: 00007FF628AD19CE v8::Isolate::ReportExternalAllocationLimitReached+94 5: 00007FF628AB67BD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62895FFCC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516 7: 00007FF62894AA4B v8::internal::NativeContextInferrer::Infer+59739 8: 00007FF62892FD1F v8::internal::MarkingWorklists::SwitchToContextSlow+56975 9: 00007FF628943A0B v8::internal::NativeContextInferrer::Infer+31003 10: 00007FF62893AAED v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6285 11: 00007FF628942C5E v8::internal::NativeContextInferrer::Infer+27502 12: 00007FF628946CAB v8::internal::NativeContextInferrer::Infer+43963 13: 00007FF6289506A2 v8::internal::ItemParallelJob::Task::RunInternal+18 14: 00007FF628950631 v8::internal::ItemParallelJob::Run+641 15: 00007FF628923C93 v8::internal::MarkingWorklists::SwitchToContextSlow+7683 16: 00007FF62893AF9C v8::internal::MarkCompactCollector::EnsureSweepingCompleted+7484 17: 00007FF6289397D4 v8::internal::MarkCompactCollector::EnsureSweepingCompleted+1396 18: 00007FF628937348 v8::internal::MarkingWorklists::SwitchToContextSlow+87224 19: 00007FF628965DB1 v8::internal::Heap::LeftTrimFixedArray+929 20: 00007FF628967EA5 v8::internal::Heap::PageFlagsAreConsistent+789 21: 00007FF62895D0C1 v8::internal::Heap::CollectGarbage+2049 22: 00007FF62895B2C5 v8::internal::Heap::AllocateExternalBackingStore+1349 23: 00007FF628975155 v8::internal::GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact+1029 24: 00007FF6289755A5 v8::internal::Factory::AllocateRaw+37 25: 00007FF62898AC9E v8::internal::FactoryBase<v8::internal::Factory>::NewStruct+94 26: 00007FF628983A95 v8::internal::Factory::NewStackTraceFrame+53 27: 00007FF6289AD0E2 v8::internal::Isolate::CaptureSimpleStackTrace+2354 28: 00007FF6289AC971 v8::internal::Isolate::CaptureSimpleStackTrace+449 29: 00007FF6289AC0BD v8::internal::Isolate::CaptureAndSetSimpleStackTrace+45 30: 00007FF6289A28A0 v8::internal::MessageLocation::MessageLocation+3664 31: 00007FF6289A63BC v8::internal::MessageFormatter::Format+13100 32: 00007FF62897ADB6 v8::internal::Factory::NewError+134 33: 00007FF628984AF2 v8::internal::Factory::NewTypeError+162 34: 00007FF6289A6561 v8::internal::MessageHandler::MakeMessageObject+337 35: 00007FF6286ABF7C v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+9596 36: 00007FF628B5CDFD v8::internal::SetupIsolateDelegate::SetupHeap+474253 37: 00007FF628AED1C9 v8::internal::SetupIsolateDelegate::SetupHeap+16473 38: 00007FF628AF2FC2 v8::internal::SetupIsolateDelegate::SetupHeap+40530 39: 0000007021B7AE30 npm ERR! code ELIFECYCLE npm ERR! errno 134 npm ERR! results-manage@0.1.0 dev: `vue-cli-service serve` npm ERR! Exit status 134 npm ERR! npm ERR! Failed at the results-manage@0.1.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! D:\softwareInstall\nvmInstall\nodejs\node_cache\_logs\2025-07-19T14_07_13_559Z-debug.log
07-20
PS D:\zhWork\202501gsykj\control_map> npm run serve > app@0.1.0 serve D:\zhWork\202501gsykj\control_map > vue-cli-service serve Browserslist: caniuse-lite is outdated. Please run: npx update-browserslist-db@latest Why you should do it regularly: https://github.com/browserslist/update-db#readme INFO Starting development server... [24%] building (3/382 modules) [24%] building (29/437 modules) [BABEL] Note: The code generator has deoptimised the styling of D:\zhWork\202501gsykj\control_map\node_modules\element-ui\lib\element-ui.common.js as it exceeds the max of[38%] building (487/784 modules) [38%] building (553/844 modules) <--- Last few GCs ---> [27132:000001FEDBF30F00] 57033 ms: Mark-sweep (reduce) 4090.3 (4101.9) -> 4089.7 (4103.4) MB, 1232.3 / 0.0 ms (average mu = 0.171, current mu = 0.004) allocation failure scavenge might not succeed [27132:000001FEDBF30F00] 58079 ms: Mark-sweep (reduce) 4090.7 (4102.4) -> 4090.2 (4103.9) MB, 1041.3 / 0.0 ms (average mu = 0.089, current mu = 0.005) allocation failure scavenge might not succeed <--- JS stacktrace ---> FATAL ERROR: MarkCompactCollector: young object promotion failed Allocation failed - JavaScript heap out of memory 1: 00007FF62825412F napi_wrap+133311 2: 00007FF6281EDD06 SSL_get_quiet_shutdown+63062 3: 00007FF6281EEB9D node::OnFatalError+301 4: 00007FF628AD19CE v8::Isolate::ReportExternalAllocationLimitReached+94 5: 00007FF628AB67BD v8::SharedArrayBuffer::Externalize+781 6: 00007FF62895FFCC v8::internal::Heap::EphemeronKeyWriteBarrierFromCode+1516 7: 00007FF62894AA4B v8::internal::NativeContextInferrer::Infer+59739 8: 00007FF62892FD1F v8::internal::MarkingWorklists::SwitchToContextSlow+56975 9: 00007FF628943A0B v8::internal::NativeContextInferrer::Infer+31003 10: 00007FF62893AAED v8::internal::MarkCompactCollector::EnsureSweepingCompleted+6285 11: 00007FF628942C5E v8::internal::NativeContextInferrer::Infer+27502 12: 00007FF628946CAB v8::internal::NativeContextInferrer::Infer+43963 13: 00007FF6289506A2 v8::internal::ItemParallelJob::Task::RunInternal+18 14: 00007FF628950631 v8::internal::ItemParallelJob::Run+641 15: 00007FF628923C93 v8::internal::MarkingWorklists::SwitchToContextSlow+7683 16: 00007FF62893AF9C v8::internal::MarkCompactCollector::EnsureSweepingCompleted+7484 17: 00007FF6289397D4 v8::internal::MarkCompactCollector::EnsureSweepingCompleted+1396 18: 00007FF628937348 v8::internal::MarkingWorklists::SwitchToContextSlow+87224 19: 00007FF628965DB1 v8::internal::Heap::LeftTrimFixedArray+929 20: 00007FF628967EA5 v8::internal::Heap::PageFlagsAreConsistent+789 21: 00007FF62895D0C1 v8::internal::Heap::CollectGarbage+2049 22: 00007FF62895B2C5 v8::internal::Heap::AllocateExternalBackingStore+1349 23: 00007FF628975155 v8::internal::GCIdleTimeHandler::ShouldDoContextDisposalMarkCompact+1029 24: 00007FF6289755A5 v8::internal::Factory::AllocateRaw+37 25: 00007FF62898AC9E v8::internal::FactoryBase<v8::internal::Factory>::NewStruct+94 26: 00007FF628983A95 v8::internal::Factory::NewStackTraceFrame+53 27: 00007FF6289AD0E2 v8::internal::Isolate::CaptureSimpleStackTrace+2354 28: 00007FF6289AC971 v8::internal::Isolate::CaptureSimpleStackTrace+449 29: 00007FF6289AC0BD v8::internal::Isolate::CaptureAndSetSimpleStackTrace+45 30: 00007FF6289A28A0 v8::internal::MessageLocation::MessageLocation+3664 31: 00007FF6289A63BC v8::internal::MessageFormatter::Format+13100 32: 00007FF62897ADB6 v8::internal::Factory::NewError+134 33: 00007FF628984AF2 v8::internal::Factory::NewTypeError+162 34: 00007FF6289A6561 v8::internal::MessageHandler::MakeMessageObject+337 35: 00007FF6286ABF7C v8::internal::interpreter::JumpTableTargetOffsets::iterator::operator=+9596 36: 00007FF628B5CDFD v8::internal::SetupIsolateDelegate::SetupHeap+474253 37: 00007FF628AED1C9 v8::internal::SetupIsolateDelegate::SetupHeap+16473 38: 00007FF628AF2FC2 v8::internal::SetupIsolateDelegate::SetupHeap+40530 39: 0000016033C23430 npm ERR! code ELIFECYCLE npm ERR! errno 134 npm ERR! app@0.1.0 serve: `vue-cli-service serve` npm ERR! Exit status 134 npm ERR! npm ERR! Failed at the app@0.1.0 serve script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! D:\softwareInstall\nvmInstall\nodejs\node_cache\_logs\2025-07-19T15_09_42_012Z-debug.log 什么问题
07-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值