Npm安装:FetchError:请求http://registry.npmjs.org / ...失败,原因:读取ECONNRESET

时间:2019-05-11 10:06:06

标签: npm raspberry-pi npm-install

尝试使用npm挂起安装任何节点软件包大约5分钟,然后出现ECONNRESET网络错误。我最近一直在将npm用于其他项目,它工作正常,但现在不适用于任何项目(包括干净的npm init)

npm i ws

这是在没有代理要求的情况下在我的家庭网络上运行的Raspberry pi 3上。 linux和Windows上的所有其他机器都可以正常工作。

npm -v = 6.4.1

我尝试了以下方法:

  1. npm i ws这给了我ECONNRESET错误(见下文)

  2. Curl https://registry.npmjs.org/Curl https://registry.npmjs.org/ws 两者都返回正确的json响应

  3. 删除任何代理设置

    npm config rm proxy
    npm config rm https-proxy
    npm config set registry http://registry.npmjs.org/
  1. 重新启动等

完整错误日志:

npm i ws --save --verbose
npm info it worked if it ends with ok
npm verb cli [ '/home/pi/.nvm/versions/node/v8.16.0/bin/node',
npm verb cli   '/home/pi/.nvm/versions/node/v8.16.0/bin/npm',
npm verb cli   'i',
npm verb cli   'ws',
npm verb cli   '--save',
npm verb cli   '--verbose' ]
npm info using npm@6.4.1
npm info using node@v8.16.0
npm verb npm-session 0a9bedb5def7f4a1
npm timing stage:rollbackFailedOptional Completed in 6ms
npm timing stage:runTopLevelLifecycles Completed in 1146975ms
npm verb type system
npm verb stack FetchError: request to http://registry.npmjs.org/ws failed, reason: read ECONNRESET
npm verb stack     at ClientRequest.req.on.err (/home/pi/.nvm/versions/node/v8.16.0/lib/node_modules/npm/node_modules/node-fetch-npm/src/index.js:68:14)
npm verb stack     at emitOne (events.js:116:13)
npm verb stack     at ClientRequest.emit (events.js:211:7)
npm verb stack     at Socket.socketErrorListener (_http_client.js:401:9)
npm verb stack     at emitOne (events.js:116:13)
npm verb stack     at Socket.emit (events.js:211:7)
npm verb stack     at emitErrorNT (internal/streams/destroy.js:66:8)
npm verb stack     at _combinedTickCallback (internal/process/next_tick.js:139:11)
npm verb stack     at process._tickCallback (internal/process/next_tick.js:181:9)
npm verb cwd /home/pi/projects/picamera/node_server
npm verb Linux 4.19.37-v7+
npm verb argv "/home/pi/.nvm/versions/node/v8.16.0/bin/node" "/home/pi/.nvm/versions/node/v8.16.0/bin/npm" "i" "ws" "--save" "--verbose"
npm verb node v8.16.0
npm verb npm  v6.4.1
npm ERR! code ECONNRESET
npm ERR! errno ECONNRESET
npm ERR! network request to http://registry.npmjs.org/ws failed, reason: read ECONNRESET
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network 
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly.  See: 'npm help config'
npm verb exit [ 1, true ]
npm timing npm Completed in 1148813ms

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/pi/.npm/_logs/2019-05-10T23_28_17_769Z-debug.log

1 个答案:

答案 0 :(得分:0)

首先检查以下内容:

ping registry.npmjs.org

您将通过以下方式了解IP地址:

PING Registry.npmjs.org(104.16.20.35)56(84)字节数据。 然后

sudo vi /etc/hosts
104.16.20.35 registry.npmjs.org

然后尝试执行以下操作

npm install