You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

nvm切换Node至v16后npm运行仍识别旧v10版本问题

问题描述

最初本地安装 Node 16.15.1,因项目B需要 Node 10 旧版本,安装 nvm 做版本管理。通过 nvm 安装 Node 10 后执行 nvm use 10 切换版本,完成了项目B的依赖安装。
之后切回项目A执行 npm run serve,编译提示当前运行环境为 Node 10。执行 nvm use 16 切换版本后再次运行命令,仍出现相同报错。此时执行 node --version 核查显示当前版本为 v16,nvm list 也显示已安装两个版本、当前激活版本为 v16。
后续卸载了两个 Node 版本,仅重装 v16 版本,运行时仍收到版本不兼容报错,相关命令输出如下:

> nvm ls 

16.15.1 (Currently using 64-bit executable)
> npm run serve

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

> single-stylist-website@0.1.0 serve
> vue-cli-service serve

 ERROR  You are using Node v10.15.2, but vue-cli-service requires Node ^12.0.0 || >= 14.0.0.
        Please upgrade your Node version.
> node --version

v16.15.1

为彻底移除 v10 版本,尝试过以下操作:

  • 删除 nvm 文件夹下所有 Node 版本文件
  • 通过控制面板卸载所有 Node 程序
  • 重启电脑,在多个新打开的 CMD 窗口测试,排除终端缓存问题
    版本切换异常的表现始终存在:从 v16 切换到 v10 可正常生效,但从 v10 切回 v16 时,运行项目始终识别到 v10 版本。

补充信息

项目 package.json 配置

{
  "name": "single-stylist-website",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "serve": "vue-cli-service serve",
    "build": "vue-cli-service build",
    "lint": "vue-cli-service lint"
  },
  "engines": {
    "node" : ">=14.0.0"
  },
  "dependencies": {
    "axios": "^0.27.2",
    "core-js": "^3.8.3",
    "npm": "^8.12.1",
    "vue": "^3.2.13",
    "vue-router": "^4.0.3",
    "vuex": "^4.0.2"
  },
  "devDependencies": {
    "@babel/core": "^7.12.16",
    "@babel/eslint-parser": "^7.12.16",
    "@vue/cli-plugin-babel": "~5.0.0",
    "@vue/cli-plugin-eslint": "~5.0.0",
    "@vue/cli-plugin-router": "~5.0.0",
    "@vue/cli-service": "~5.0.0",
    "eslint": "^7.32.0",
    "eslint-plugin-vue": "^8.0.3"
  },
  "eslintConfig": {
    "root": true,
    "env": {
      "node": true
    },
    "extends": [
      "plugin:vue/vue3-essential",
      "eslint:recommended"
    ],
    "parserOptions": {
      "parser": "@babel/eslint-parser"
    },
    "rules": {}
  },
  "browserslist": [
    "> 1%",
    "last 2 versions",
    "not dead",
    "not ie 11"
  ]
}

排查测试结果

新建空项目后,将原项目除 node_modules 外的所有文件复制到新项目,执行 npm install 后再运行 npm run serve 可正常启动。


根因与修复

查阅 nvm 官方文档可知,安装 nvm 前需先卸载系统中原有的独立安装版 Node,否则会出现环境变量路径优先级冲突,导致版本切换逻辑异常。
最终修复方案:彻底删除本地所有 node、npm、nvm 相关文件,清理对应系统环境变量后重新配置 nvm 环境,问题完全解决。


内容的提问来源于stack exchange,提问作者Nicoara

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.03 08:36:27