简介

本文介绍如何解决git的报错:exited with error code: 128

问题复现

使用npm install命令下载前端项目(本处是vue-element-admin项目)的依赖,报了如下错误:

npm WARN deprecated source-map-resolve@0.5.3: See https://github.com/lydell/source-map-resolve#deprecated
npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated source-map-url@0.4.1: See https://github.com/lydell/source-map-url#deprecated
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
npm ERR! Error while executing:
npm ERR! d:\Program Files\Git\cmd\git.EXE 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: 20.205.243.166]: errno=No such file or directory
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!     E:\work\npm\node_cache\_logs\2022-06-03T00_25_44_783Z-debug.log

原因分析

       有的库有改动,不能通过git://访问了,这时我们可以改为使用https://来访问。

解决方案

在请求git://地址时,自动替换为https://,命令如下:

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

执行完上边的命令之后,再执行npm install,就能成功了:

E:\work\WebStorm_proj\frontend_others\vue-element-admin>npm install
npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
npm WARN deprecated chokidar@2.1.5: Chokidar 2 does not receive security updates since 2019. Upgrade to chokidar 3 with 15x fewer dependencies
npm WARN deprecated html-webpack-plugin@3.2.0: 3.x is no longer supported
 
> ejs@2.7.4 postinstall E:\work\WebStorm_proj\frontend_others\vue-element-admin\node_modules\ejs
> node ./postinstall.js
 
......
 
> core-js@2.6.12 postinstall E:\work\WebStorm_proj\frontend_others\vue-element-admin\node_modules\node-plop\node_modules\core-js
> node -e "try{require('./postinstall')}catch(e){}"
 
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.2 (node_modules\watchpack\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\watchpack-chokidar2\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\jest-haste-map\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\webpack-dev-server\node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.2.7 (node_modules\chokidar\node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
 
added 2043 packages from 2006 contributors in 69.461s
 
103 packages are looking for funding
  run `npm fund` for details

备注

如果想删除这个设置,命令如下:

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

url.<base>.insteadOf详解

官网:https://git-scm.com/docs/git-config#Documentation/git-config.txt-urlltbasegtinsteadOf

官网介绍

url.<base>.insteadOf

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐