执行npm install报错无法连接到github.com的问题

报错信息如下:

Step 6/11 : RUN npm install
 ---> Running in fbea7757df0b
npm WARN ub-arc-mgmt@4.2.1 license should be a valid SPDX license expression

npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t git://github.com/adobe-webplatform/eve.git
npm ERR! 
npm ERR! fatal: unable to connect to github.com:
npm ERR! github.com[0: 52.74.223.119]: errno=Connection timed out
npm ERR! 
npm ERR! 
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-02-27T09_03_17_432Z-debug.log

 

场景:

在用docker 构建vue node项目镜像时,执行npm install 命令是包连接不上github.com

网上搜索到解决方案:

参考:

https://www.daxiblog.com/npm-install%e8%a7%a3%e5%86%b3fatal-unable-to-connect-to-github-com%e9%97%ae%e9%a2%98/

引用上文的解释:

意思是我连接不上github。但是不可能啊,我能够访问github的官网。而且在其他工程里执行npm install都能很顺利执行完成了。看来很有可能是上面截图中eve.git这个库的引用防止有些不太一致造成的。于是在通过在网络上搜寻,找到了原因所在:

上图中可以看到这个eve.git这个库的引用是通过git写引用的。git协议的默认端口是9418,很有可能是我的网络环境防火墙并没有开放这个端口造成的。解决方法就是,用https替代git协议。配置的命令为:

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

docker 中解决方案:

在Dockerfile中执行npm install之前,执行上述命令

修改如下:

//解决npn install报错连接不上git的问题。
RUN git config --global url."https://".insteadOf git://
RUN npm install

 

后续npm install问题接龙:

1、npm ERR! Failed at the node-sass@4.13.0 postinstall script.

gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/home/erms/uicode/ub-arc-mgmt-gui/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Linux 3.10.0-693.el7.x86_64
gyp ERR! command "/root/.nvm/versions/node/v12.13.1/bin/node" "/home/erms/uicode/ub-arc-mgmt-gui/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
gyp ERR! cwd /home/erms/uicode/ub-arc-mgmt-gui/node_modules/node-sass
gyp ERR! node -v v12.13.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok 
Build failed with error code: 1
npm WARN ub-arc-mgmt@4.2.1 license should be a valid SPDX license expression
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! node-sass@4.13.0 postinstall: `node scripts/build.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-sass@4.13.0 postinstall script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2020-03-01T12_04_15_682Z-debug.log

解决:

这个是因为sass安装时获取源的问题,先修改sass安装的源,再运行npm install就成功了

npm config set sass_binary_site=https://npm.taobao.org/mirrors/node-sass

 

  • 8
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值