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

更新后npm无法运行,抛出TypeError错误求助

问题描述

在Node.js终端中查看node版本(v16.17.0)和npm版本时一切正常,但在VS Code或PowerShell中执行npm -v命令时,出现如下错误:

C:\Program Files\nodejs\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> (C:\Program Files\nodejs\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:110:44)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:174:29)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\remote.js:7:18)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
C:\Program Files\nodejs\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> (C:\Program Files\nodejs\node_modules\npm\node_modules\socks-proxy-agent\dist\index.js:110:44)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\agent.js:174:29)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1180:10)
    at Module.load (node:internal/modules/cjs/loader:1004:32)
    at Function.Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1028:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\make-fetch-happen\lib\remote.js:7:18)
    at Module._compile (node:internal/modules/cjs/loader:1126:14)
解决方案

该错误源于socks-proxy-agent依赖的agent-base版本不兼容,或代理配置冲突,可按以下步骤解决:

  • 清理代理配置
    执行命令清除npm代理设置:

    npm config rm proxy
    npm config rm https-proxy
    

    同时检查系统环境变量中的HTTP_PROXY和HTTPS_PROXY,如有配置,暂时删除或禁用。

  • 重新安装全局npm
    直接更新npm到最新版本:

    npm install -g npm@latest
    

    若上述命令失败,可通过Node内置脚本重装npm:

    node -e "fs.rmSync('C:\\Program Files\\nodejs\\node_modules\\npm', { recursive: true, force: true })"
    curl -L https://www.npmjs.com/install.sh | node
    
  • 校验终端Node环境一致性
    在VS Code和PowerShell中执行Get-Command node(Windows)或which node(类Unix),确认使用的Node路径与Node.js终端一致,避免多版本冲突。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.20 17:48:30