react-native init AwesomeProject 无法连接到 github.com [英] react-native init AwesomeProject unable to connect to github.com
问题描述
我遵循了 facebook 发布的教程.开始使用 https://facebook.github.io/react-native/docs/getting-started.html#content
I followed the tutorial posted by facebook. Getting startted https://facebook.github.io/react-native/docs/getting-started.html#content
但是,当我运行 react-native init AwesomeProject 时,我只会收到以下错误.我的node.js是v4.1.0,npm是v2.14.3.
however, when I run react-native init AwesomeProject, I only get the following errors. My node.js is v4.1.0, npm is v2.14.3.
不知道是我的环境还好还是无法连接到github.com?
I don't know if my environment is ok or it just can not connect to github.com?
npm 错误!git clone --template=/Users/jansenli/.npm/_git-remotes/_templates --mirror git://github.com/facebook/react.git/Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b:致命:无法连接到 github.com:
npm ERR! git clone --template=/Users/jansenli/.npm/_git-remotes/_templates --mirror git://github.com/facebook/react.git /Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b: fatal: unable to connect to github.com:
npm 错误!git clone --template=/Users/jansenli/.npm/_git-remotes/_templates --mirror git://github.com/facebook/react.git/Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b: github.com[0: 192.30.252.129]: errno=操作超时
npm ERR! git clone --template=/Users/jansenli/.npm/_git-remotes/_templates --mirror git://github.com/facebook/react.git /Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b: github.com[0: 192.30.252.129]: errno=Operation timed out
npm 错误!达尔文 14.5.0
npm ERR! Darwin 14.5.0
npm 错误!argv "/Users/jansenli/.nvm/versions/node/v4.1.0/bin/node" "/Users/jansenli/.nvm/versions/node/v4.1.0/bin/npm" "安装" "--save" "反应原生"
npm ERR! argv "/Users/jansenli/.nvm/versions/node/v4.1.0/bin/node" "/Users/jansenli/.nvm/versions/node/v4.1.0/bin/npm" "install" "--save" "react-native"
npm 错误!节点 v4.1.0
npm ERR! node v4.1.0
npm 错误!npm v2.14.3
npm ERR! npm v2.14.3
npm 错误!代码 128
npm ERR! code 128
npm 错误!命令失败: git clone --template=/Users/jansenli/.npm/_git-remotes/_templates --mirror git://github.com/facebook/react.git/Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b
npm ERR! Command failed: git clone --template=/Users/jansenli/.npm/_git-remotes/_templates --mirror git://github.com/facebook/react.git /Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b
npm 错误!克隆到裸仓库 '/Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b'...
npm ERR! Cloning into bare repository '/Users/jansenli/.npm/_git-remotes/git-github-com-facebook-react-git-baa2986b'...
npm 错误!致命:无法连接到 github.com:
npm ERR! fatal: unable to connect to github.com:
npm 错误!github.com[0: 192.30.252.129]: errno=操作超时
npm ERR! github.com[0: 192.30.252.129]: errno=Operation timed out
npm 错误!
npm 错误!
npm 错误!
npm 错误!如果您需要帮助,可以在以下位置报告此错误:
npm ERR! If you need help, you may report this error at:
npm 错误!https://github.com/npm/npm/issues
npm 错误!请在任何支持请求中包含以下文件:
npm ERR! Please include the following file with any support request:
npm 错误!/Users/jansenli/AwesomeProject/npm-debug.log
npm ERR! /Users/jansenli/AwesomeProject/npm-debug.log
npm install --save react-native
失败
推荐答案
首先 - 检查您是否真的可以看到 github 网站.只需转到 https://github.com/facebook/react,您就会看到 react 项目.如果你能看到,那已经很好了:)
First - check if you can actually see github website at all. Just go to https://github.com/facebook/react and you should see the react project. If you can see, that's already good :).
然而,错误消息表明您在通过 git://github.com/facebook/:react.git 下载 repo 时遇到问题.您可以通过运行来验证:
The error messages indicate however that you have problem with downloading the repo via git://github.com/facebook/:react.git. You can validate that by running:
git clone git://github.com/facebook/react.git
它应该挂起,您也应该超时.
It should hang and you should get timeout as well.
如果您无法使用 git://连接,并且同时您可以通过 https 连接到 github - 我的猜测是您的防火墙阻止了通过端口 9418 连接到 github 的 git 协议(更多关于 git 协议在这里: https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#The-Git-Protocol).你会超时,如果你在公司防火墙后面,这是非常标准的行为.
If you cannot connect with git:// and if at the same time you can connect to github via https - my wild guess is that you have firewall blocking git protocol via port 9418 connections to github (more about the git protocol here: https://git-scm.com/book/en/v2/Git-on-the-Server-The-Protocols#The-Git-Protocol). You get timeout, which is pretty standard behaviour if you are behind company firewall.
如果是这样,那么选择就很少了.首先 - 绕过防火墙 - 比如在家里做或其他什么......但是如果你不能这样做,那么你可以尝试让 git 总是使用 https://而不是 git://.显然这两个命令会以这种方式配置 git(我没有尝试过,但应该可以):
If that's the case, then there are few options. First - bypass the firewall - like do it from home or something ... If you cannot do it however, then you can try to let git always use https:// instead of git://. Apparently those two commands will configure git in this way (I have not tried it, but it should work):
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
可能只有第一个命令就足够了(但我不确定是否 100%).
Likely only the first command should be enough (but I am not 100% sure if it is).
这篇关于react-native init AwesomeProject 无法连接到 github.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!