简体   繁体   中英

react-native init gives ESOCKETTIMEDOUT error

I am using a Macbook and when I try to create a React Native app, it throws ESOCKETTIMEDOUT error.

I have tried to clean the npm and yarn cache however it doesn't help.

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.

I am able to download the https://registry.yarnpkg.com/lodash/-/lodash-4.17.11.tgz file through my browser, so it can't be networking issue.

Stacktrace

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

Had the same issue when retrieving big packages on a slow network. As suggested on this comment , increasing the network timeout for installing the packages worked for me.

Firstly, have your project directory created beforehand and then create a .yarnrc file inside of it having the following content:

network-timeout 600000

Now, just run the react-native init <project_name> command from the parent directory of your project as you did.


It is equivalent to running yarn like so:

yarn install --network-timeout 600000

If npm can be used, please use 'npm install' - generates package-lock.json or 'yarn install --network-timeout ' - generates yarn.lock. Both works for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM