Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm install from git use https instead ssh

Tags:

git

npm

I have an application with the following package.json file

"dependencies": {
    "package_name": "git+ssh://[email protected]:Domain/package_name.git",
}

I can't change it and I can't use ssh. I tried

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

But npm i still throws an error about permission and I see that the url doesn't contain https protocol.

npm ERR! Error while executing:
npm ERR! path to git.exe ls-remote -h -t [email protected]:Domain/repo.git

Is it possible to setup git or npm to use https instead of ssh while installing deps from package.json?

like image 653
Alexey Sh. Avatar asked Apr 05 '20 23:04

Alexey Sh.


People also ask

Is it better to use SSH or HTTPS Git?

While SSH is usually considered more secure, for basic usage of Github, HTTPS authentication with a password is acceptable enough. In fact, Github themselves defaults to and recommends most people use HTTPS.

Does npm use HTTPS?

npm has accepted HTTPS or HTTP requests for some time. (In fact, only the initial hop from your client to Fastly, our CDN, would use HTTP.) We returned most data to you via HTTPS, but we would serve JSON containing package metadata over HTTP if you requested it via HTTP.

Does npm use SSH?

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


1 Answers

git config --global url."https://github.com/".insteadOf [email protected]:
git config --global url."https://".insteadOf git://

This works perfectly. Also pay attention to the colon at the end of the first line.

like image 115
Alexey Sh. Avatar answered Nov 15 '22 09:11

Alexey Sh.