当前位置:   article > 正文

执行npm install报错无法连接到github.com的问题_前端能访问镜像源,但install时报连接问题

前端能访问镜像源,但install时报连接问题

报错信息如下:

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之前,执行上述命令

修改如下:

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

 

后续npm install问题接龙:

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

  1. gyp ERR! build error
  2. gyp ERR! stack Error: `make` failed with exit code: 2
  3. gyp ERR! stack at ChildProcess.onExit (/home/erms/uicode/ub-arc-mgmt-gui/node_modules/node-gyp/lib/build.js:262:23)
  4. gyp ERR! stack at ChildProcess.emit (events.js:210:5)
  5. gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
  6. gyp ERR! System Linux 3.10.0-693.el7.x86_64
  7. 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="
  8. gyp ERR! cwd /home/erms/uicode/ub-arc-mgmt-gui/node_modules/node-sass
  9. gyp ERR! node -v v12.13.1
  10. gyp ERR! node-gyp -v v3.8.0
  11. gyp ERR! not ok
  12. Build failed with error code: 1
  13. npm WARN ub-arc-mgmt@4.2.1 license should be a valid SPDX license expression
  14. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
  15. npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
  16. npm ERR! code ELIFECYCLE
  17. npm ERR! errno 1
  18. npm ERR! node-sass@4.13.0 postinstall: `node scripts/build.js`
  19. npm ERR! Exit status 1
  20. npm ERR!
  21. npm ERR! Failed at the node-sass@4.13.0 postinstall script.
  22. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  23. npm ERR! A complete log of this run can be found in:
  24. 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

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/174609
推荐阅读
相关标签
  

闽ICP备14008679号