root@iZ2zecacx22uir8ou95g65Z:~# npm -v
报错
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module ‘…/lib/utils/unsupported.js’
Require stack:
- /opt/node/lib/node_modules/npm/bin/npm-cli.js
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at /opt/node/lib/node_modules/npm/bin/npm-cli.js:19:21
at Object. (/opt/node/lib/node_modules/npm/bin/npm-cli.js:155:3)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14) {
code: ‘MODULE_NOT_FOUND’,
requireStack: [ ‘/opt/node/lib/node_modules/npm/bin/npm-cli.js’ ]
}
解决
试尽各种办法,最后还是手动卸载了再重装了npm
1、sudo npm uninstall npm -g
如果步骤1卸不掉npm了(我就是这种情况)
2、进到npm的安装目录 /opt/node/lib/node_modules/npm (这是我的地址)
sudo make uninstall
3、手动重装npm
curl -L https://npmjs.com/install.sh | sh
控制版本
$ npm install -g n