35

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
  • 31,830
  • 51
  • 195
  • 300
  • 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://docs.microsoft.com/en-us/azure/devops/artifacts/npm/npmrc?view=azure-devops&tabs=windows – David Klempfner Jul 13 '20 at 07:02

7 Answers7

61

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

Abdullah Faruk
  • 777
  • 6
  • 8
  • 3
    That worked for me. In my case, it was "npm install -g @vue/cli" that was printing 401. What's the purpose of this solution? – Tuna Yagci Nov 28 '18 at 07:02
  • 9
    What if you need the .npmrc file for authentication to a service on a vpn? – sdfsdf Dec 04 '18 at 19:30
17

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,514
  • 14
  • 25
12

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,472
  • 1
  • 11
  • 13
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
  • 558,509
  • 191
  • 1,911
  • 1,506
0

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

Now it works fine!

Allan Almeida
  • 46
  • 1
  • 6
0

removing the .npmrc from the root directory worked for me

-3

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

Vivek Kodira
  • 2,470
  • 4
  • 29
  • 49