使用gitee导入仓库功能解决服务器无法访问github仓库的问题

背景

最近在处理一个老项目,使用的是 nodejs , 在进行 npm install 和 bower install 都出现各种问题,主要原因就是服务器无法访问github造成相关的依赖包无法安装,解决办法在此记录一下。

错误信息

bower install 出现的问题如下:

bower jquery#^3.1.1      ECMDERR Failed to execute "git ls-remote --tags --heads https://github.com/jquery/jquery-dist.git", exit code of #128 fatal: unable to access 'https://github.com/jquery/jquery-dist.git/': Failed connect to github.com:443; Connection timed out

Additional error details:
fatal: unable to access 'https://github.com/jquery/jquery-dist.git/': Failed connect to github.com:443; Connection timed out

原因

当 bower install 执行时会根据 bower.json 文件中定义的依赖包进行安装,而此时安装包只写的是依赖包名称不包含地址,所以默认会从github进行下载,而国内服务器访问github又不稳定,所以出现链接问题。

  "dependencies": {
    "angular": "~1.5",
    "angular-ui-utils": "~0.2.3",
    ......
    "jquery": "^3.1.1",
    "newrelic-angular": "^0.2.2"
  },

解决办法

尝试过的方法:

  1. 修改hosts,将github.com的地址进行重新映射,如:

    140.82.121.4 github.com
  2. 使用代理,设置 http 和 https 代理,如:

    export http_proxy="http://IP:PORT"
    export https_proxy="http://IP:PORT"
  3. 安装v2ray,使用 proxychains4 代理 v2ray 科学上网,如:

    proxychains4 bower install
  4. 替换请求中 git:// 为 https:// 如:

    git config --global url."https://".insteadOf git://

以上方法在某些情况下是可以使用的,可以多试试,但是我这里就怎么都不成功。最终使用到 gitee 的仓库导入功能,将github的仓库导入到gitee,将原地址修改为gitee的地址解决了问题。

步骤如下

  1. 根据错误信息,我们得到了有问题的项目github仓库地址为:https://github.com/jquery/jquery-dist.git

  2. 打卡gitee,右上角点击“+”,选择“ 从 GitHub / GitLab 导入仓库”

    file

  3. 填入 github 仓库的地址,会自动检测当前项目在gitee上是否已经有同样的公开库,有的话也可以直接使用,也可以自行导入,仓库名称和路径会自动识别填入,仓库介绍手动填入,点击“导入”。

    file

  4. 等待导入处理

    file

  5. 导入完成后,点击“管理”,将项目设置为“开源”

    file

  6. 此时得到该项目在gitee的地址为 https://gitee.com/alexchenx/jquery-dist.git

    file

  7. 修改 bower.json 文件

    将原来  "jquery": "^3.1.1",
    改为    "jquery": "https://gitee.com/alexchenx/jquery-dist.git#^3.1.1",
  8. 再次执行 bower install 就成功了。其他仓库同样按此方法。

版权声明:
作者:admin
链接:https://www.chenxie.net/archives/2691.html
来源:蜀小陈
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>
文章目录
关闭
目 录