首页 > 解决方案 > 安装 ReactNative CLI 时出现 NPM 安装错误

问题描述

我希望将 React Native CLI 安装到我的 Windows 10 x64 PC。请帮忙。

发出此命令时遇到以下错误:

npm install -g react-native-cli

我收到的错误:

npm ERR! code ECONNREFUSED
npm ERR! errno ECONNREFUSED
npm ERR! FetchError: request to http://registry.npmjs.org/react-native-cli failed, reason: connect ECONNREFUSED 104.16.21.35:80 - Local (0.0.0.0:2623)
npm ERR!     at ClientRequest.req.on.err (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR!     at ClientRequest.emit (events.js:182:13)
npm ERR!     at Socket.socketErrorListener (_http_client.js:391:9)
npm ERR!     at Socket.emit (events.js:182:13)
npm ERR!     at emitErrorNT (internal/streams/destroy.js:82:8)
npm ERR!     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
npm ERR!     at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR!  { FetchError: request to http://registry.npmjs.org/react-native-cli failed, reason: connect ECONNREFUSED 104.16.21.35:80 - Local (0.0.0.0:2623)
npm ERR!     at ClientRequest.req.on.err (C:\Program Files\nodejs\node_modules\npm\node_modules\node-fetch-npm\src\index.js:68:14)
npm ERR!     at ClientRequest.emit (events.js:182:13)
npm ERR!     at Socket.socketErrorListener (_http_client.js:391:9)
npm ERR!     at Socket.emit (events.js:182:13)
npm ERR!     at emitErrorNT (internal/streams/destroy.js:82:8)
npm ERR!     at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
npm ERR!     at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR!   message:
npm ERR!    'request to http://registry.npmjs.org/react-native-cli failed, reason: connect ECONNREFUSED 104.16.21.35:80 - Local (0.0.0.0:2623)',
npm ERR!   type: 'system',
npm ERR!   errno: 'ECONNREFUSED',
npm ERR!   code: 'ECONNREFUSED',
npm ERR!   stack:
npm ERR!    'FetchError: request to http://registry.npmjs.org/react-native-cli failed, reason: connect ECONNREFUSED 104.16.21.35:80 - Local (0.0.0.0:2623)\n    at ClientRequest.req.on.err (C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-fetch-npm\\src\\index.js:68:14)\n    at ClientRequest.emit (events.js:182:13)\n    at Socket.socketErrorListener (_http_client.js:391:9)\n    at Socket.emit (events.js:182:13)\n    at emitErrorNT (internal/streams/destroy.js:82:8)\n    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)\n    at process._tickCallback (internal/process/next_tick.js:63:19)' }
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\mwaqa\AppData\Roaming\npm-cache\_logs\2018-12-11T14_13_07_498Z-debug.log

标签: react-nativeexpo

解决方案


此问题可能与您的代理有关,首先,请尝试以下命令:

npm config set proxy null
npm config set https-proxy null
npm config set registry http://registry.npmjs.org/

然后执行

npm install -g react-native-cli

希望这会有所帮助。


推荐阅读