npm ERR! code 128 npm ERR! An unknown git error occurre如何解决

3,034 阅读2分钟

持续创作,加速成长!这是我参与「掘金日新计划 · 10 月更文挑战」的第10天,点击查看活动详情

1.发现问题

我在通过git工具clone vue-element-admin之后,需要下载相关的第三方包

  • 所以我就在对应目录下执行npm install开始下载文件

image.png 但是下载到一半就开始报错

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git clone git@gitee.com:panjiachen/vue-admin-template.git hrsaas
npm ERR! git@github.com: Permission denied (publickey).
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.

npm ERR! A complete log of this run can be found in:
npm ERR!     D:\Develo\nodejs\node_cache\_logs\2022-02-23T03_34_18_949Z-debug-0.log

翻译了一下意思是:

npm犯错!代码128

npm犯错!发生了未知的git错误

npm犯错!命令git——no-replace-objects ls-remote ssh://git@github.com/adobe-webplatform/eve.git

npm犯错!git@github.com:拒绝权限(publickey)。

npm犯错!致命的:无法从远程存储库读取。

npm犯错!

npm犯错!请确保您拥有正确的访问权限

npm犯错!而且存储库已经存在。

大概是路径错误,没有权限和已经有存储库

2.搜索解决方案

2.1方案一:ssh更换为https

1、使用下面的命令,达到,把地址里的 ​​ssh://git@​​​ 换成 ​​https://​​ 的目的

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

2、然后重新通过 npm install 安装项目依赖

npm install
  • 这个方案看着没什么问题,但是我是失败了,还是无法解决问题
  • 不过不同人的情况不同,也许这个方法对你有用

2.2方案二:重新部署ssh公钥

1.打开git命令框

image.png

2.输入命名生成ssh公钥

ssh-keygen -t rsa -C "xxxxx@xxxxx.com"//此处填写你的git账号邮箱,我的是gitee账号

出现以下代码,敲一下回车即可

image.png

出现以下代码,再敲一下回车即可 image.png

出现以下代码,再敲一下回车即可 image.png

最后结果如图,表示ssh秘钥生成成功

image.png

3.获取公钥

在git页面输入

cat ~/.ssh/id_rsa.pub

获取到ssh公钥

image.png 复制这串公钥到gitee的公钥管理处

https://gitee.com/profile/sshkeys

image.png

粘贴公钥

image.png 点击添加即可

4.然后重新通过 npm install 安装项目依赖

npm install

  • 下载成功,问题解决

image.png

3.总结

3.1在git页面不能使用ctrl+c/v的方式复制粘贴,只能使用右键copy和paste

image.png

3.2其他git仓库

我使用的gitee下载,如果你使用的是github或者其他git仓库出现这个问题

  • 可以配置对应的仓库公钥
  • 操作方法应该是类似的

3.3重写秘钥

如果原来就有对应的公钥, 在git命令时,他会问你是否重写秘钥(overwrite)

image.png

  • 此处我选择y(yes)重写秘钥
  • 然后进行2.2的操作