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

发布时间 2023-06-11 13:24:10作者: chccee

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

 

1.发现问题

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

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

在安装依赖包node_models开始报错无法安装

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犯错!而且存储库已经存在。



错误原因是因为没有gitlab权限和已经有存储库

2.解决方案

2.1方案一:ssh更换为https

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

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

2、需要填写gielab的账号和密码,Select a credential helper弹框选择manager

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

npm install

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

 

2.输入命名生成ssh公钥

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

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

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

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

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

 

3.获取公钥

cat ~/.ssh/id_rsa.pub

获取到ssh公钥

 制这串公钥到gitlab的公钥管理处

 

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

npm install即可

原链接:https://juejin.cn/post/7151597684028096519