FredyC FredyC - 3 months ago 341
Git Question

Install npm module from gitlab private repository

We are using GitLab for our private project. There are some forked libraries from github, that we want to install as npm module. Installing that module directly from npm is ok and for example this:

npm install git://github.com/FredyC/grunt-stylus-sprite.git


...works correctly too, but doing the same for GitLab, just changing domain gets me this error.

npm WARN `git config --get remote.origin.url` returned wrong result (git://git.domain.com/library/grunt-stylus-sprite.git)
npm ERR! git clone git://git.domain.com/library/grunt-stylus-sprite.git Cloning into bare repository 'D:\users\Fredy\AppData\Roaming\npm-cache\_git-remotes\git-git-domain-com-library-grunt-stylus-sprite-git-6f33bc59'...
npm ERR! git clone git://git.domain.com/library/grunt-stylus-sprite.git fatal:unable to connect to git.domain.com:
npm ERR! git clone git://git.domain.com/library/grunt-stylus-sprite.git git.domain.com[0: 77.93.195.214]: errno=No error
npm ERR! Error: Command failed: Cloning into bare repository 'D:\users\Fredy\App
Data\Roaming\npm-cache\_git-remotes\git-git-domain-com-library-grunt-stylus-spr
ite-git-6f33bc59'...
npm ERR! fatal: unable to connect to git.domain.com:
npm ERR! git.domain.com[0: xx.xx.xx.xx]: errno=No error


From the web interface of GitLab, I have this URL
git@git.domain.com:library/grunt-stylus-sprite.git
. Running this against
npm install
it tries to install
git
module from npm registry.

However using URL:
git+ssh@git.domain.com:library/grunt-stylus-sprite.git
is suddenly asking me for the password. My SSH key doesn't include passphrase, so I assume it wasn't able to load that key. Maybe there is some configuration for that I have missed ? Key is located at standard location in my home directory with the name
"id_rsa"
.

I am on Windows 7 x64.

UPDATE

Since NPM v3 there is built-in support for GitLab and other sources (BitBucket, Gist), from where you can install packages. Unfortunately it works only for public ones so it's not exactly related to this, but some might find it useful.

npm install gitlab:<gitlabname>/<gitlabrepo>[#<commit-ish>]


Check out documentation: https://docs.npmjs.com/cli/install

Answer

I had the same issue using a private instance of GitLab. Taking from the existing answers you're able to use the privately hosted repositories with the following;

git+ssh://git@git.mydomain.com:Username/Repository#{branch|tag}