react-native - react-native init 给出 ESOCKETTIMEDOUT 错误
问题描述
我正在使用 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
解决方案
在慢速网络上检索大包时遇到同样的问题。正如此评论所建议的,增加安装软件包的网络超时对我有用。
首先,预先创建您的项目目录,然后在其中创建一个.yarnrc
包含以下内容的文件:
network-timeout 600000
现在,只需react-native init <project_name>
像以前一样从项目的父目录运行命令。
相当于这样运行yarn
:
yarn install --network-timeout 600000
推荐阅读
- python - 如何使用 xarray 提取最近坐标的变量值?
- javascript - 将 XMLHttpRequest 数据动态渲染到 Vue 元素
- google-chrome - 如果 Google 删除了我的扩展程序,它是否仍安装在计算机上?
- mysql - MySQL如何使用存储过程创建数据库用户?
- mysql - 无法在字段注册 (uid) 和登录 (uid) 上的两个表之间添加外键
- c# - 如何将电子邮件确认码作为 html 链接发送?
- python - 我的 RST README 在 PyPi 上的格式不正确
- node.js - 使用 Nodemailer 发送电子邮件时如何修复 ReferenceError
- discord.py - 更改虚拟机后找不到命令错误
- polymorphism - int list -> int 而不是 'a list -> 'a