Jav*_*hip 5 git ssh npm package.json
我有以下package.json文件,我正在尝试运行npm install,但失败。
"test": "git+https://<TOKEN>@github.build.test.com/test.git",
Run Code Online (Sandbox Code Playgroud)
我有与github匹配的ssh密钥。但是,即使我编写以下内容,它也始终使用https运行。
"test": "git+ssh://git@github.build.test.com/test.git",
Run Code Online (Sandbox Code Playgroud)
在两种情况下,我都会遇到以下错误消息
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
Run Code Online (Sandbox Code Playgroud)
如果我单独运行上面的命令,它可以工作。
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
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
谢谢
首先,如果你的 git 配置中有任何url.<base>.insteadOf指令:
cd /path/to/repo
git config -l|grep -i insteadOf
Run Code Online (Sandbox Code Playgroud)
如果没有,请设置您自己的之一:
git config url."ssh://git@github.build.test.com".insteadOf https://github.build.test.com
Run Code Online (Sandbox Code Playgroud)
然后看看它是否仍在使用 https。