npm安装hexo报错FetchError,代理127.0.0.1:1080问题

代理127.0.0.1:1080问题

$ npm install -g hexo-cli
npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to http://registry.cnpmjs.org/hexo-cli failed, reason: connect ECONNREFUSED 127.0.0.1:1080
npm ERR! at ClientRequest. (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:310:20)
npm ERR! at Socket.socketErrorListener (_http_client.js:426:9)
npm ERR! at Socket.emit (events.js:310:20)
npm ERR! at emitErrorNT (internal/streams/destroy.js:92:8)
npm ERR! at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
npm ERR! at processTicksAndRejections (internal/process/task_queues.js:84:21)
npm ERR! FetchError: request to http://registry.cnpmjs.org/hexo-cli failed, reason: connect ECONNREFUSED 127.0.0.1:1080
npm ERR! at ClientRequest. (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR! at ClientRequest.emit (events.js:310:20)
npm ERR! at Socket.socketErrorListener (_http_client.js:426:9)
npm ERR! at Socket.emit (events.js:310:20)
npm ERR! at emitErrorNT (internal/streams/destroy.js:92:8)
npm ERR! at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
npm ERR! at processTicksAndRejections (internal/process/task_queues.js:84:21) {
npm ERR! type: ‘system’,
npm ERR! errno: ‘ECONNREFUSED’,
npm ERR! code: ‘ECONNREFUSED’
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\bianh\AppData\Roaming\npm-cache_logs\2020-05-28T14_13_40_286Z-debug.log
npm安装hexo报错FetchError,代理127.0.0.1:1080问题_第1张图片

解决办法:

  1. 先清除掉以前的代理设置
npm config set proxy null
npm config set https-proxy null
npm config delete proxy
npm config delete https-proxy

也可以先通过以下代码查看代理设置,如果返回null那就不需要清理。

npm config get proxy
npm config get https-proxy
  1. 重新设置
npm config set registry http://registry.cnpmjs.org/
npm config set registry "http://registry.npmjs.org/"

或者安装一下cnpm
npm install -g cnpm –registry=https://registry.npm.taobao.org

npm安装hexo报错FetchError,代理127.0.0.1:1080问题_第2张图片

其他
npm设置代理

设置代理
npm config set proxy=http://127.0.0.1:8087
npm config set registry=http://registry.npmjs.org

关于https
经过上面设置使用了http开头的源,因此不需要设https_proxy了,否则还要增加一句:

npm config set https-proxy http://server:port

代理用户名和密码
npm config set proxy http://username:password@server:port
npm confit set https-proxy http://username:password@server:port

你可能感兴趣的:(hexo,npm)