I'm facing this error when I'm trying to install Angular CLI. Please help me with the issue:

npm ERR! code E401
npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm"

9 Answers 9


In my case, I have set registry via npm config set registry <corporate_registry_url> an authenticated via npm login and I had this 401 error until I've added to .npmrc config file this line


after the following line


This way, token got applied and installation of a package succeeded.

  • My bad, I didn't realise you wrote "...I've added to .npmrc..." Jan 10, 2022 at 23:02
  • 1
    @DavidKlempfner right, I've made it a bit more visible
    – YakovL
    Jan 11, 2022 at 15:30

I was trying to setup npm for the first time on my laptop. My corporate npm registry is in Artifactory. I had configured my auth through the .npmrc file by adding the below details to it (as suggested in Artifactory "set me up"):

[email protected]

The error (npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm") got resolved after removing underscore (_) from auth in the .npmrc file:

[email protected]
  • This actually worked ! tried so many things but this is what actually worked ...Thanks !
    – Zaid
    Nov 2, 2020 at 15:36
  • Solution that actually worked! Thank you so much :)
    – Learner
    Jan 18, 2022 at 13:14
  • Didn't work for me. Jan 22, 2022 at 16:46
  • didn't work for me either
    – logoff
    Mar 31, 2022 at 7:41

Looks like you're running into authentication issues with your company's internal npm registry. I'd try one of these solutions:

  • Talk with your DevOps team and figure out why your login isn't working. This is the type of thing that a company ought to document in a wiki or similar place.
  • Try adding --registry https://registry.npmjs.org to your npm commands in the short term. This will install from the public registry, which you should not need to authenticate to.

If you run npm config ls, you will likely see a registry line. There should be a filename above it ending in .npmrc; if you edit this file you can change the registry to the public one. (Usually it's ~/.npmrc but may depend on your configuration.)

  • 2
    Usually people use a local registry because their firewalls restrict access such that they can't connect the registry.npmjs.org. If that is the case, your suggestion won't work.
    – Lee Meador
    Apr 24, 2020 at 18:22

Adding following in .npmrc worked for me:

_auth = <Basic_Authentication_Header>
email = [email protected]
always-auth = true

Online utility which can help to generate Basic Authentication Header can be found here - https://www.blitter.se/utils/basic-authentication-header-generator/

  • 1
    Thanks, this actually worked for me too. Had to add scope at the top as well: @jfrog:registry=https://yourcompany.registry.com/artifactory then running npm install --scope=jfrog --save package-name worked like a charm Mar 25, 2021 at 10:30

It helps if you post your NPM configs. Use npm config ls to see what registry you have set up. I ran into a similar error message and my solution was to set the registry as secured HTTP: registry=https://.... I'm also using my job's Artifactory server. Once you set the registry, you can try authenticating against the Artifactory registry using npm login, which will prompt you for username, password, and the e-mail address associated with your Artifactory registry account.

This Artifactory endpoint will retrieve an encrypted auth token (which can be used for reaching the Artifactory API) and e-mail:

curl -vv -<username>:<encrypted-password> http://<ARTIFACTORY-HOST</artifactory/api/npm/auth

You can get <encrypted-password> usually by going to your Artifactory account in the browser at https://<artifactory-host>/artifactory/webapp/#/profile.

Sample output:

_auth = <encrypted-auth-token>
always-auth = true
email = [email protected]

What worked for me:

  1. Ran

npm config ls

Look for the location/path of where .npmrc - next to text: userconfig

  1. Go to that location/path then delete the .nprmc file

  2. Ran the in npm install command - e.g:

npm install cypress --save-dev


what worked for me is :

I deleted the .npmrc file under C/users/ folder. and ran npx vsts-npm-auth -config .npmrc command to create a new file in the users folder


I ran into this issue because we recently integrated AWS CodeArtifact into our platform, and I forgot to run

aws codeartifact login --tool npm --domain {MY_DOMAIN} --domain-owner {MY_AWS_ACCOUNT} --repository {MY_REPOSITORY}

Which will overwrite your .npmrc file with proper authentication

vsts-npm-auth -config .npmrc -F

Is the only solution I found

Make sure to run npm install -g vsts-npm-auth before

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .