解决 npm install 时npm ERR! code 128npm ERR! An unknown git error occurrednpm ERR!(下载vue-element-admin)

这是我在下载 vue-element-admin 时遇到的问题

具体错误代码为

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! 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!     C:\Users\lin\AppData\Local\npm-cache\_logs\2023-07-02T16_09_33_887Z-debug-0.log

网上有很多方法如

1. 改 git 配置   (对我没效果)

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

2. 清理缓存 ( 对我也没效果 )

接下来说下我是如何解决的

我是通过在 github 上配置ssh key

  1. 检查本地主机是否已经存在ssh key
    执行 ls ~/.ssh   用 git bash 运行  右键随便文件夹可以看到
    ls ~/.ssh
    //看是否存在 id_rsa 和 id_rsa.pub文件,如果存在,说明已经有SSH Key

  2. 如果存在,直接跳到第三步

    生成ssh key

    如果不存在ssh key,可以使用以下命令生成

    ssh-keygen -t rsa -C "xxx@xxx.com"
    //执行后一直回车即可

    代码参数含义:

    -t 指定密钥类型,默认是 rsa ,可以省略。
    -C 设置注释文字,比如邮箱。
    -f 指定密钥文件存储文件名。

    生成完以后再用第二步命令,查看ssh key

  3. 获取ssh key公钥内容(id_rsa.pub)
    clip < ~/.ssh/id_rsa.pub
    // 这行代码可以直接把 ssh key 保存在剪切板,避免自己复制错误

  4. Github账号上添加公钥  进入 Settings 配置

        添加ssh key,把刚才复制的内容粘贴上去保存即可

5. 验证是否成功

ssh -T git@github.com

        显示下面信息就是成功了

        

接下来在运行 npm install 就成功了,

没成功有可能网络问题也有可能我的方法有问题。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值