问题描述
NPM卸载高版本后安装低版本运行报错:
bash
C:\Users\Administrator>npm -v
ERROR: npm v10.2.1 is known not to run on Node.js v10.24.1. This version of npm supports the following node versions: `^18.17.0 || >=20.5.0`. You can find the latest version at https://nodejs.org/.
ERROR:
C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\lib\utils\exit-handler.js:19
const hasLoadedNpm = npm?.config.loaded
^
SyntaxError: Unexpected token .
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at module.exports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\lib\cli-entry.js:15:23)
at module.exports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\lib\es6\validate-engines.js:39:10)
at module.exports (C:\Users\Administrator\AppData\Roaming\npm\node_modules\npm\lib\cli.js:4:31)
解决方案
删除目录C:\Users\Administrator\AppData\Roaming
下的npm
和npm-cache
目录后重新安装。