25

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"

10 Answers 10

13

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

//<repo_url>:always-auth=true

after the following line

//<repo_url>:_authToken=<token>

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

1
  • 1
    @DavidKlempfner right, I've made it a bit more visible
    – YakovL
    Commented Jan 11, 2022 at 15:30
10

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"):

_auth=xxxxxxxxxxxx
always-auth=true
[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:

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

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.)

1
  • 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
    Commented Apr 24, 2020 at 18:22
5

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
  • 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 Commented Mar 25, 2021 at 10:30
3

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

2

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]
0

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

0

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

0
vsts-npm-auth -config .npmrc -F

Is the only solution I found

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

0

I faced this error. the issue was the Password, I used '$' sign and made this error, I used another symbol and my problem was solved.

You must log in to answer this question.

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