【问题标题】:npm install from git use https instead ssh从 git 安装 npm 使用 https 而不是 ssh
【发布时间】:2022-03-30 22:48:08
【问题描述】:

我有一个包含以下 package.json 文件的应用程序

"dependencies": {
    "package_name": "git+ssh://git@git.scm.domain.com:Domain/package_name.git",
}

我无法更改它,也无法使用 ssh。我试过了

git config --global url.https://.insteadOf git://
git config --global url.https://git.scm.domain.com.insteadOf git://git.scm.domain.com

但是npm i 仍然会抛出关于权限的错误,并且我看到该 url 不包含 https 协议。

npm ERR! Error while executing:
npm ERR! path to git.exe ls-remote -h -t git@git.scm.domain.com:Domain/repo.git

在从 package.json 安装 deps 时,是否可以设置 git 或 npm 以使用 https 而不是 ssh?

【问题讨论】:

  • git+ssh://git@git.scm.domain.com 是一个 SSH URL,而您的替代品使用 git:// 协议。
  • @phd 我刚刚更新了问题。请检查 npm 错误。没有git+ssh
  • 您的 JSON 文件示例包含 git+ssh://,这是 ssh:// 的旧同义词。此外,该 URL 是否包含冒号或斜杠?它永远不会与冒号一起工作。

标签: git npm


【解决方案1】:
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://

这非常有效。还要注意第一行的冒号 末尾。

【讨论】:

    【解决方案2】:
    git config --global url."https://".insteadOf ssh://
    

    这个对我有用。

    【讨论】:

    • 我想npm 的最新版本需要这个。
    【解决方案3】:

    我需要手动删除 package-lock.json 中有问题的包条目/引用,然后运行 ​​Alexey 的答案中的两个命令。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-14
      • 2019-07-29
      • 2012-08-15
      • 1970-01-01
      • 2019-05-29
      • 2022-07-13
      • 1970-01-01
      • 2020-06-10
      相关资源
      最近更新 更多