Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install fails due to private git repository both ssh and https connections

I have the following package.json file and I am trying to run npm install, but it fails.

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

I have ssh key matched to github. However even I write the following, it always run with https.

    "test": "git+ssh://[email protected]/test.git",

In both case, I encounter following error message

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

If I run above command separately, it works.

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

How can I fix it?

Thanks

like image 270
Can Cinar Avatar asked Jan 03 '19 05:01

Can Cinar


People also ask

Does NPM use SSH?

[BUG] NPM v7 uses SSH instead of an explicit HTTPS for GitHub repos #2610.

Could not read from remote repository NPM install?

You may encounter this error when installing npm. This happens when you list a git repository as a dependency in your package. json file. If the repository is private, add an additional SSH key in Project settings > SSH Keys > Additional SSH Keys.


1 Answers

First if you have any url.<base>.insteadOf directive in your git configuration:

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

And if not, set one of your own:

git config url."ssh://[email protected]".insteadOf  https://github.build.test.com

See then if it is still using https.

like image 83
VonC Avatar answered Nov 15 '22 04:11

VonC