basickarl
basickarl

Reputation: 40464

NPM install resulting in 401 Unauthorized for private repo

I have the following line in my dependencies in package.json:

"log": "https://git.mydomain.com/myproject/myrepo/repository/archive.tar.gz?ref=0.1.0",

I get the following:

km@Karls-MBP ~/dev/vertica (km/ref) $ npm install
npm ERR! code E401
npm ERR! 404 401 Unauthorized: log@https://git.mydomain.com/myproject/myrepo/repository/archive.tar.gz?ref=0.5.0

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/km/.npm/_logs/2018-02-16T08_49_38_669Y-debug.log

I don't know if the issue is GitLab (where the repo exists) or NPM.

Upvotes: 56

Views: 149672

Answers (8)

Nikita
Nikita

Reputation: 235

I added auth token for my artifactory to project's .npmrc like

//artifactory:_auth={token}

token is base64 of email:artifactoryToken

Upvotes: 0

Ahmed Elkoussy
Ahmed Elkoussy

Reputation: 8568

I got the same error but the reason in my case was different than the above answers:

I discovered that the package-lock.json had some of the packages resolved to a private url instead of the typical public npm urls, so deleting the npm lock file and running npm install again solved it

But if this is the case, you need to check with the team still why this private url resolution happened instead of the normal one

Upvotes: 3

Allan Almeida
Allan Almeida

Reputation: 100

In my case I have to change the content of .npmrc file to package-lock=false.

Now it works fine!

Upvotes: 0

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657308

I got this when I used --prefer-offline

- npm ci --cache .npm --prefer-offline --unsafe-perm --no-optional

Removing that option fixed it.

Upvotes: 0

Salah Atwa
Salah Atwa

Reputation: 1728

You need to add user to npm registery

>> npm whoami [ it will return not authorized ]

To add new user follow below steps :-

>> npm adduser  (then enter your name and complex password and your email)

>> npm whoami   (return your registered name)

Upvotes: 18

Vivek Kodira
Vivek Kodira

Reputation: 2914

I noticed this error for a public github repo. Removed the entry always-auth = true and was able to proceed.

Upvotes: -3

santon
santon

Reputation: 1834

My user directory .npmrc file had a stale authtoken as below.

//registry.npmjs.org/:_authToken=3615fa68-123a-4d72-b99a-772b5b1edc48

By removing this line, the npm installation works fine and no longer throws an authentication error.

Upvotes: 20

Abdullah Faruk
Abdullah Faruk

Reputation: 1011

Remove .npmrc from the Home Directory, it should be able to work. I did the same and it works for me.

Upvotes: 83

Related Questions