【问题标题】:npm install fails due to private git repository both ssh and https connections由于 ssh 和 https 连接的私有 git 存储库,npm 安装失败
【发布时间】:2019-05-29 17:20:30
【问题描述】:

我有以下 package.json 文件,我正在尝试运行 npm install,但它失败了。

    "test": "git+https://<TOKEN>@github.build.test.com/test.git",

我有与 github 匹配的 ssh 密钥。但是,即使我写了以下内容,它也总是使用 https 运行。

    "test": "git+ssh://git@github.build.test.com/test.git",

在这两种情况下,我都会遇到以下错误消息

npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t https://github.build.test.com/test.git
npm ERR!
npm ERR! remote: Password authentication is not available for Git operations.
npm ERR! remote: You must use a personal access token or SSH key.
npm ERR! remote: See https://github.build.test.com/settings/tokens or https://github.build.test.com/settings/ssh
npm ERR! fatal: unable to access 'https://github.build.test.com/test.git/': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128

如果我单独运行上面的命令,它可以工作。

git ls-remote -h -t https://<TOKEN>@github.build.test.com/test.git
git ls-remote -h -t ssh://git@github.build.test.com/test.git

我该如何解决?

谢谢

【问题讨论】:

  • @Vix 我的答案缺少什么?您可以编辑问题并分享有关您的具体案例的更多详细信息吗?

标签: git npm ssh package.json


【解决方案1】:

如果您打算使用“git+ssh://git@github.build.test.com/test.git”,您应该能够在不传递凭据的情况下克隆此存储库。 简单的git clone git+ssh://git@github.build.test.com/test.git 不应要求提供密码或用户名。

您可能需要配置您的 git 公钥/私钥。您本地使用的克隆密钥必须添加到存储库配置中。例如对于 github 可以在https://github.com/settings/keys上配置它

【讨论】:

    【解决方案2】:

    首先,如果你的 git 配置中有 url.&lt;base&gt;.insteadOf directive

    cd /path/to/repo
    git config -l|grep -i insteadOf
    

    如果没有,请自己设置一个:

    git config url."ssh://git@github.build.test.com".insteadOf  https://github.build.test.com
    

    然后看看它是否还在使用 https。

    【讨论】:

      猜你喜欢
      • 2021-11-28
      • 1970-01-01
      • 1970-01-01
      • 2022-09-28
      • 1970-01-01
      • 2013-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多