react-native init 给出 ESOCKETTIMEDOUT 错误

标签 react-native npm yarnpkg

我正在使用 Macbook,当我尝试创建 React Native 应用程序时,它抛出 ESOCKETTIMEDOUT错误。

我试图清理 npm 和 yarn 缓存,但它没有帮助。

react-native init AwesomeProject
This will walk you through creating a new React Native project in /Users/gaurang.shah/Documents/personal/code/mobile/AwesomeProject
Using yarn v1.13.0
Installing react-native...
yarn add v1.13.0
info No lockfile found.
[1/4] 🔍  Resolving packages...
[2/4] 🚚  Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz: ESOCKETTIMEDOUT".
info If you think this is a bug, please open a bug report with the information provided in "/Users/gaurang.shah/Documents/personal/code/mobile/AwesomeProject/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

我可以下载 https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz文件通过我的浏览器,所以它不可能是网络问题。

堆栈跟踪
Yarn version:
  1.13.0

Node version:
  11.10.0

Platform:
  darwin x64

Trace:
  Error: https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz: ESOCKETTIMEDOUT
      at ClientRequest.<anonymous> (/usr/local/Cellar/yarn/1.13.0/libexec/lib/cli.js:130024:19)
      at Object.onceWrapper (events.js:285:13)
      at ClientRequest.emit (events.js:197:13)
      at TLSSocket.emitRequestTimeout (_http_client.js:669:40)
      at Object.onceWrapper (events.js:285:13)
      at TLSSocket.emit (events.js:197:13)
      at TLSSocket.Socket._onTimeout (net.js:447:8)
      at listOnTimeout (timers.js:327:15)
      at processTimers (timers.js:271:5)

npm manifest:
  {"name":"AwesomeProject","version":"0.0.1","private":true,"scripts":{"start":"node node_modules/react-native/local-cli/cli.js start"}}

yarn manifest:
  No manifest

Lockfile:
  No lockfile

最佳答案

在慢速网络上检索大包时遇到同样的问题。正如在此建议的 comment ,增加安装软件包的网络超时对我有用。

首先,预先创建您的项目目录,然后创建一个 .yarnrc其中的文件具有以下内容:

network-timeout 600000

现在,只需运行 react-native init <project_name>像您一样从项目的父目录中执行命令。

相当于运行yarn像这样:

yarn install --network-timeout 600000

关于react-native init 给出 ESOCKETTIMEDOUT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54818471/

相关文章:

react-native - 通过expo运行react-native项目网页版的网页版时出错。消息是 - 无法编译/Libraries/StyleSheet/processColor.js

react-native - 不能总是在 Chrome 中设置 React Native 断点

react-native - 在 react-native-router-flux 中禁用特定场景的 header

node.js - 如何将npm包中的node.js对象存储在mongodb中

npm - 将库从依赖项重定位到 package.json 中的 devDependencies block 的命令?

android - 如何解决 react native 和 android sdk 之间的重复类错误?

node.js - 即使 npm 二进制文件就在那里,终端也不会打开它

webpack - 将 postcss-loader 从 3.0.0 迁移到 4.0.2 会导致错误 : [object Object] is not a PostCSS plugin

javascript - Yarn Workspaces,工作区不会发出错误或警告

javascript - 使用 'opn' npm 模块在 Docker 中未处理的 promise 拒绝