51

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.

  • Node v8.9.4
  • NPM v5.6.0
basickarl
  • 37,187
  • 64
  • 214
  • 335
  • Is the tarball publicly available? If not, you'll need to provide an auth strategy in the package URL. Have you seen [this](https://stackoverflow.com/a/28729646/382982) question/answer? Also, it seems unlikely that it'd be an NPM issue, but just in case: try `npm logout && npm login`, ensure there isn't either a stale `$NPM_TOKEN` env var or `_authToken` set in an .npmrc (look in your home directory and the project directory). – pdoherty926 Feb 16 '18 at 11:53
  • 1
    I had to follow these steps to fix the error: https://learn.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc?view=azure-devops&tabs=windows – David Klempfner Jul 13 '20 at 07:02

9 Answers9

73

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

Abdullah Faruk
  • 913
  • 8
  • 8
18

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.

santon
  • 1,654
  • 16
  • 26
16

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)
Salah Atwa
  • 1,648
  • 2
  • 12
  • 13
1

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

Ahmed Elkoussy
  • 8,162
  • 10
  • 60
  • 85
0

I got this when I used --prefer-offline

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

Removing that option fixed it.

Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
0

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

Now it works fine!

Allan Almeida
  • 90
  • 1
  • 2
  • 8
-1

removing the .npmrc from the root directory worked for me

-1

removing the .npmrc from the root directory worked perfectly for me as well

-3

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

Vivek Kodira
  • 2,764
  • 4
  • 31
  • 49