Getting “npm ERR! Unable to authenticate, need: Basic realm="Artifactory Realm"” when attempting to install Angular CLI
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"
Solution 1:
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.
Solution 2:
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 yournpm
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.)
Solution 3:
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]
Solution 4:
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]
Solution 5:
What worked for me:
- Ran
npm config ls
Look for the location/path of where .npmrc - next to text: userconfig
-
Go to that location/path then delete the .nprmc file
-
Ran the in npm install command - e.g:
npm install cypress --save-dev