【问题标题】:react-native init gives ESOCKETTIMEDOUT errorreact-native init 给出 ESOCKETTIMEDOUT 错误
【发布时间】:2019-07-16 00:56:50
【问题描述】:

我使用的是 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

【问题讨论】:

    标签: react-native npm yarnpkg


    【解决方案1】:

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

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

    network-timeout 600000
    

    现在,只需从项目的父目录运行react-native init &lt;project_name&gt; 命令即可。


    相当于像这样运行yarn

    yarn install --network-timeout 600000
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-17
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 2019-11-15
      • 2020-10-19
      • 1970-01-01
      • 2017-04-24
      相关资源
      最近更新 更多