从 git 安装 npm 使用 https 代替 ssh

Ale*_*Sh. 4 git npm

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

"dependencies": {
    "package_name": "git+ssh://git@git.scm.domain.com:Domain/package_name.git",
}
Run Code Online (Sandbox Code Playgroud)

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

git config --global url.https://.insteadOf git://
git config --global url.https://git.scm.domain.com.insteadOf git://git.scm.domain.com
Run Code Online (Sandbox Code Playgroud)

但是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
Run Code Online (Sandbox Code Playgroud)

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

Aks*_*801 19

git config --global url."https://".insteadOf ssh://
Run Code Online (Sandbox Code Playgroud)

这对我有用。

  • 我想最近版本的“npm”需要这个。 (2认同)

Ale*_*Sh. 5

git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
Run Code Online (Sandbox Code Playgroud)

这完美地工作。还要注意第一行末尾冒号