简单说明一下报错信息:使用npm install安装任何包都会报错,errno ECONNREFUSED,报错信息如下:

$ npm install --save hexo-blog-encrypt
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! code ECONNREFUSED
npm ERR! syscall connect
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to https://registry.npmmirror.com/hexo-blog-encrypt failed, reason: connect ECONNREFUSED 127.0.0.1:31181
npm ERR!     at ClientRequest.<anonymous> (E:\Program Files\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:527:28)
npm ERR!     at onerror (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR!     at callbackError (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:96:5)
npm ERR!  FetchError: request to https://registry.npmmirror.com/hexo-blog-encrypt failed, reason: connect ECONNREFUSED 127.0.0.1:31181
npm ERR!     at ClientRequest.<anonymous> (E:\Program Files\nodejs\node_modules\npm\node_modules\minipass-fetch\lib\index.js:130:14)
npm ERR!     at ClientRequest.emit (node:events:527:28)
npm ERR!     at onerror (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:117:21)
npm ERR!     at callbackError (E:\Program Files\nodejs\node_modules\npm\node_modules\agent-base\dist\src\index.js:136:17)
npm ERR!     at processTicksAndRejections (node:internal/process/task_queues:96: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!   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:
npm ERR!     C:\Users\Administrator\AppData\Local\npm-cache\_logs\2023-04-11T05_46_04_410Z-debug-0.log

当我出现这个问题时,以为是镜像源出错,就一直在更换镜像源,结果可想而知,依旧没有解决错误,在不断查找资料发现自己的方向就错了,这个问题的核心错误信息是:

reason: connect ECONNREFUSED 127.0.0.1:31181
问题的原因:

一般来说是访问国外网站工具或者加速器开启了网络代理,修改了相关配置导致 npm连接本机 31181 端口安装包。

首先可以查看一下npm的代理配置:

npm config get https-proxy

http://127.0.0.1:31181/

 然后查看本地的端口没有对应的服务开启:

netstat -ano

 到这基本就可以确定是代理导致的问题。

解决办法:

1.清空相关代理,http-proxy和proxy

npm config delete https-proxy
npm config delete proxy

2.查看配置代理的结果

npm config get proxy
//返回null
npm config get https-proxy
//返回null

由上图可知,当两者都返回null时说明删除成功,此时在修改镜像源才可能有用。

3.之后安装即可

npm i axios
参考资料:
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐