1.案发现场

当执行npm install 安装的时候可能会出现如下报错信息:

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects ls-remote ssh://git@github.com/nhn/raphael.git
npm ERR! git@github.com: Permission denied (publickey).
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!     C:\Users\XXXX\AppData\Local\npm-cache\_logs\2023-01-03T07_20_29_806Z-debug-0.log

2 故障分析

错误日志中有如下关键信息:

Please make sure you have the correct access rights npm ERR! and the repository exists.

意思是我们对这个仓库没有操作权限,但是按说不可能哈,这是一个github 开源库,不应该需要权限哈。

仔细观察未登录github访问这个仓库发现:
在这里插入图片描述
??? 压根没有ssh 下载选项

github 登陆后再看看发现有了。
在这里插入图片描述

顿时明了,由于这个前端开源框架很坑的下载第三方依赖用的是ssh ssh://git@github.com/nhn/raphael.git 方式下载,

而这种方式下载,必须配置了访问github 的ssh key 才可以

3 解决方案

配置访问github 的ssh key 即可。

如果有多个代码仓库,可以通过 .ssh/config 分别配置多个ssh key 即可。

示例如下:

# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

# aliyun code
Host git@code.aliyun.com
HostName git@code.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

# aliyun code up
Host git@codeup.aliyun.com
HostName git@codeup.aliyun.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

# company gitlab
#Host git.xxxx.cn
#HostName git.xxx.cn
#PreferredAuthentications publickey
#IdentityFile ~/.ssh/company_id_rsa

具体生成ssh key 方法 参考 阿里云Code SSH KEY 代码入库

4. 参考文献

Logo

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

更多推荐