Installing NPM packages from GitLab repositories

15th February, 2015 — Aral Balkan

TL; DR: If you want to install an NPM package from a GitLab repository, use the git+https (or git+http) protocol, not git:// or https://.

This one always catches me out. If you want to specify that an NPM package should be installed from a GitLab repository (e.g., from source.ind.ie), you need to use the git+https protocol (or HTTP if you’re being naughty and running GitLab without TLS).

package.json{
  …
  "dependencies": {
    "indie-set": "git+https://source.ind.ie/project/set.git",
  …
  }
}

This catches me out as git:// URLs work for GitHub repositories. So, for example, the following is perfectly valid and works:

package.json{
  …
  "dependencies": {
    "ws": "git://github.com/websockets/ws.git",
  …
  }
}

If you try that with GitLab, however, you’ll get an error message similar to:

npm ERR! git clone git://source.ind.ie/project/set.git Cloning into bare repository '/Users/aral/.npm/_git-remotes/git-source-ind-ie-project-set-git-445a3a05'...
npm ERR! git clone git://source.ind.ie/project/set.git fatal: unable to connect to source.ind.ie:
npm ERR! git clone git://source.ind.ie/project/set.git source.ind.ie[0: 37.139.13.136]: errno=Connection refused
npm ERR! Darwin 14.1.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v0.12.0
npm ERR! npm  v2.5.1
npm ERR! code 128

npm ERR! Command failed: git clone --template=/Users/aral/.npm/_git-remotes/_templates --mirror git://source.ind.ie/project/set.git /Users/aral/.npm/_git-remotes/git-source-ind-ie-project-set-git-445a3a05
npm ERR! Cloning into bare repository '/Users/aral/.npm/_git-remotes/git-source-ind-ie-project-set-git-445a3a05'...
npm ERR! fatal: unable to connect to source.ind.ie:
npm ERR! source.ind.ie[0: 37.139.13.136]: errno=Connection refused

And if you try to install it using just the https protocol, you’ll get an error similar to:

npm WARN package.json labs@0.0.1 No repository field.
npm ERR! fetch failed https://source.ind.ie/project/set.git
npm WARN retry will retry, error on last attempt: Error: fetch failed with status code 406