解决npm问题:错误的代理设置

发布于:2025-02-24 ⋅ 阅读:(12) ⋅ 点赞:(0)

错误的代理设置

npm install vue-waterfall-plugin-next
npm ERR! code ECONNREFUSED
npm ERR! syscall connect
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmmirror.com/vue-waterfall-plugin-next failed, reason: connect ECONNREFUSED 127.0.0.1:31181
npm ERR!     at ClientRequest.<anonymous> (F:\Tools\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:517:28)
npm ERR!     at onerror (F:\Tools\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR!     at callbackError (F:\Tools\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
npm ERR!  FetchError: request to https://registry.npmmirror.com/vue-waterfall-plugin-next failed, reason: connect ECONNREFUSED 127.0.0.1:31181
npm ERR!     at ClientRequest.<anonymous> (F:\Tools\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:517:28)
npm ERR!     at onerror (F:\Tools\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR!     at callbackError (F:\Tools\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect',
npm ERR!   address: '127.0.0.1',
npm ERR!   port: 31181,
npm ERR!   type: 'system',
npm ERR!     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect',
npm ERR!   address: '127.0.0.1',
npm ERR!   port: 31181,
npm ERR!   type: 'system',
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   syscall: 'connect',
npm ERR!   address: '127.0.0.1',
npm ERR!   port: 31181,
npm ERR!   type: 'system',
npm ERR!   syscall: 'connect',
npm ERR!   address: '127.0.0.1',
npm ERR!   port: 31181,
npm ERR!   type: 'system',
npm ERR!   type: 'system',
npm ERR!   requiredBy: '.'
npm ERR! }
npm ERR!
npm ERR! If you are behind a proxy, please make sure that the
npm ERR! 'proxy' config is set properly.  See: 'npm help config'

npm ERR! A complete log of this run can be found in: F:\Tools\nodejs\node_cache\_logs\2025-02-20T01_02_46_768Z-debug-0.log

遇到此问题是因为 npm 配置了错误的代理设置,导致尝试通过本地未被监听的端口(127.0.0.1:31181)进行连接。以下是分步解决方案:

步骤 1:清除 npm 的代理配置

在命令行中执行以下命令,移除可能存在的代理设置:

npm config delete proxy
npm config delete https-proxy

步骤 2:检查环境变量中的代理设置

确保没有设置 HTTP_PROXYHTTPS_PROXY 环境变量。在 Windows 的 CMD 中运行:

set HTTP_PROXY
set HTTPS_PROXY

如果发现这些变量被设置,需要取消设置。在 CMD 中:

set HTTP_PROXY=
set HTTPS_PROXY=

在环境变量中将 HTTP_PROXY和 HTTPS_PROXY 删除
重新npm install xxx 即可成功。