12

I'm trying to install NPM dependencies from a private GitLab instence.

So, I have my repo with basic files

enter image description here

And I added this dependencie in the package.json on my project

"node-demo-package": "https://oauth2:<ACCESS TOKEN>@gitlab.fullurl.git"

But, when I run npm install, I receive this error message:

npm ERR! code ENOPACKAGEJSON
npm ERR! package.json Non-registry package missing package.json: node-demo-package@https://oauth2:<ACCESS TOKEN>@gitlab.fullurl.git.
npm ERR! package.json npm can't find a package.json file in your current directory.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/arnaud.delante/.npm/_logs/2018-01-24T15_05_49_456Z-debug.log

Which I don't understand as there is a package.json as showed in the screenshot.

Here it is

{
  "name": "demo-package",
  "version": "1.0.0",
  "description": "Test pasckage",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git@gitlab.fullurl.git"
  },
  "author": "Arnaud Delante",
  "license": "MIT"
}

I already tried switching https by git+https but I get another error

npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://oauth2:<ACCES TOKEN>@gitlab.fullrul.git
npm ERR!
npm ERR! remote: You are not allowed to download code from this project.
npm ERR! fatal: unable to access 'https://oauth2:<ACCES TOKEN>@gitlab.fullrul.git': The requested URL returned error: 403
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/arnaud.delante/.npm/_logs/2018-01-24T17_19_16_677Z-debug.log

Which is weird because the token is correct.

Would you have any idea?

Axiol
  • 5,664
  • 9
  • 37
  • 49
  • Is oauth2 a user in gitlab ? Is it working from command line ? – Gabriel Bleu Jan 24 '18 at 17:38
  • @GabrielBleu Yep, I just double-check and all credentials are correct – Axiol Jan 25 '18 at 09:10
  • 1
    @GabrielBleu I also tried changing the type of access token I was using. First I was using a read repository only token and I try swicth to a full API token. With the second one, I don't have any error, but the module is not installed (can't find it in `node_modules`) – Axiol Jan 25 '18 at 09:39

1 Answers1

7

In package.json try to replace https:// by git+https://

doc : https://docs.npmjs.com/files/package.json#git-urls-as-dependencies

Gabriel Bleu
  • 9,703
  • 2
  • 30
  • 43
  • I actually already tried that and I also get an error (I edited my question with the detail of the error) – Axiol Jan 24 '18 at 17:21
  • Adventurer, all 3 parts of the protocol must be gathered and the trinity combined for access tokens to work with private npm repositories on Gitlab, `git+https://:@gitlab.com/.git` – Vix Apr 16 '19 at 16:25