在 NPM 运行任意指令时,均会报以下错误:
/usr/local/lib/node_modules/npm/node_modules/socks-proxy-agent/dist/index.js:110
class SocksProxyAgent extends agent_base_1.Agent {
^
TypeError: Class extends value undefined is not a constructor or null
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/socks-proxy-agent/dist/index.js:110:44)
at Module._compile (node:internal/modules/cjs/loader:1165:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
at Module.load (node:internal/modules/cjs/loader:1043:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1067:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/make-fetch-happen/lib/agent.js:174:29)
at Module._compile (node:internal/modules/cjs/loader:1165:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
at Module.load (node:internal/modules/cjs/loader:1043:32)
at Function.Module._load (node:internal/modules/cjs/loader:878:12)
at Module.require (node:internal/modules/cjs/loader:1067:19)
at require (node:internal/modules/cjs/helpers:103:18)
at Object.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/make-fetch-happen/lib/remote.js:7:18)
at Module._compile (node:internal/modules/cjs/loader:1165:14)
出现该情况大概率是在切换 node
版本时,npm
版本过低导致的。
我是使用的 n
模块来切换版本的。
解决方案:
- 先切换回旧的
node
版本; - 更新
npm
:
$ npm i -g npm
- 再尝试切换回新的
node
版本; - 重新运行相关
npm
命令即可;