npm ERR! code E401 npm ERR! Incorrect or missing password
Asked Answered
H

19

75

My Node version is 10.15.0 and NPM version is 6.8.4 On running npm install after upgrading npm to 14.16.0 and npm to 7.6.2

Getting this error -

npm ERR! code E401
npm ERR! Incorrect or missing password.
npm ERR! If you were trying to login, change your password, create an
npm ERR! authentication token or enable two-factor authentication then
npm ERR! that means you likely typed your password in incorrectly.
npm ERR! Please try again, or recover your password at:
npm ERR!     https://www.npmjs.com/forgot
npm ERR! 
npm ERR! If you were doing some other operation then your saved credentials are
npm ERR! probably out of date. To correct this please try logging in again with:
npm ERR!     npm login

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xyz/.npm/_logs/2021-04-15T18_55_07_993Z-debug.log
Holmquist answered 15/4, 2021 at 19:6 Comment(3)
In my case, I fixed this issue by adding a new Private Access Token in Azure DevOps. Then I had to Base64 encode it and add it to .npmrc ...Maybe this approach helps somebody else as well.Nolpros
I had a similar problem connecting to an Azure DevOps feed. I ran this command to update my access token: vsts-npm-auth -F -C .npmrcLiking
At last a great working solution !! thanks, @LikingAnadromous
C
83
  1. Try Deleting the package-lock.json file before running the command "npm install" after upgrading the node versions, if you have not done that.

  2. If that will not work try removing the .npmrc file in $HOME directory as mentioned in this post.

NPM ERR Code E401: Unable to authenticate, need: Bearer authorization

Note - Deleting package-lock.json can have its own issues as mentioned in this posts, so go with this solution unless you find any better solution.

Deleting `package-lock.json` to Resolve Conflicts quickly

Casemaker answered 15/4, 2021 at 19:13 Comment(4)
Yep I totally missed that. Removing the package-lock.json worked for me. Thanks!Holmquist
See this SO answer for potential reasons why you may not want to delete package-lock.json.Estafette
In my case, I fixed this issue by adding a new Private Access Token in Azure DevOps. Then I had to Base64 encode it and add it to .npmrc ...Maybe this approach helps somebody else as well.Nolpros
Can you explain what's causing the issue in the first place?Parclose
E
13

In the directory C/Users/your-windows-username/

delete the following files:

.cache
.package
.package-lock
.npmrc

After that, go to your project and run the following command in your terminal

npm i
Elliot answered 4/8, 2021 at 5:57 Comment(3)
I only found the .cache, but that and deleting the package-lock.json file fixed it. Thank you. I would never in a million years have figured this one out.Mcintosh
clear .npmrc did the trick for meInsulation
Be careful blowing away your .cache directory, as it's used by pip and other package managers.Ghetto
R
12

I had the same error with the company registry configured in .npmrc

registry=https:<company-registry-url>

Node version : 19.1.0
NPM version : 8.19.3

Solution:

Execute npm login

$ npm login
npm notice Log in on https:<registry-url>
Username: xxxx
Password:
Email: (this IS public) (xxxx)
Logged in as xxx on https:<registry-url>.

After this .npmrc got updated with

//<registry-url>/:_authToken=xxxxx
Resentful answered 16/2, 2022 at 4:42 Comment(1)
Worked thanks! I had company npm artifactory registered at Jfrog.Transferase
L
5

Your password in .npmrc must be base64 encoded. Easy to screw up just copy-pasting the password, need to base64 encode that.

Lisp answered 7/11, 2022 at 20:0 Comment(0)
G
4

I have been getting the same error recently on various projects after running npm run dev:

npm ERR! code E401
npm ERR! Incorrect or missing password.

What fixed it for me was to delete my package-lock.json file (and any yarn.lock files, which might create conflicts with npm) and the node_modules directory. Then I updated my npm packages with npm update. (CAUTION: Before updating any npm packages, you should probably create a new Git branch and run npm update in that new branch. If you run into bigger problems after the updates, then you can revert back to your previous branch.)

After my packages were updated, then running my npm startup script (e.g. npm run dev) worked again without errors.

NOTE: You can run npm outdated to see which of your npm packages could use an update.

Gunfire answered 1/2, 2022 at 23:59 Comment(0)
P
3

If you configured your .npmrc, maybe your credentials are expired or need new credentials. Try this vsts-npm-auth -config .npmrc. If it gives you this error [The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.] try with vsts-npm-auth -config .npmrc -force. That should generate new credentials.

Priorate answered 13/6, 2023 at 17:7 Comment(0)
D
1

Look at the specified log file (e. g. /Users/xyz/.npm/_logs/2021-04-15T18_55_07_993Z-debug.log). It could be that a 3rd party or corporate package to be installed requires authentication.

For example, if you try to install the pro icons of FontAwesome and the authentication (token) is missing, this error occurs.

Dearman answered 21/2, 2023 at 18:56 Comment(1)
This actually helped me and turned out to be my exact problem (hadn't copied the .npmrc file over) so thank you!Hatshepsut
I
1

In my case, I encountered this error while dealing with the Azure Artifacts feed. By generating a new Personal Access Token (PAT) in Azure DevOps and using its Base64 encoded value in my .npmrc file, I was able to resolve this issue.

Invaluable answered 27/9, 2023 at 15:23 Comment(0)
L
1

in my case, I just tried npm login, entered the credentials, logged in ( in my case it was GUI, in your case it might be in terminal ) and then ran the desired npm command again ( it was npm run test in my case ) and it worked!

Libby answered 27/5 at 8:5 Comment(0)
M
0

Had the same issue with Node 16.x.x. I have done everything from this topic and those topics which were mentioned here and nothing helped me!

The only thing that helped me to login was that I have deleted Node 16.x.x and installed Node 14.8.1 from here - https://nodejs.org/en/download/releases/

Malodorous answered 18/1, 2022 at 16:33 Comment(0)
B
0

It can be happening because of a bug on npm. This was happening to me with npm v7. Switched to v6 and it worked.

More context: https://github.com/npm/cli/pull/2153

Biotechnology answered 17/2, 2022 at 16:23 Comment(0)
T
0

What worked for me is:

npm login    
npm notice Log in on https://www.SOME_URL.com
Username: xyz
Password:
Email: (this IS public) (USER_EMAIL_ID.com)
Logged in as xyz on https://www.SOME_URL.com

and then npm login. All dependencies installed

Typeset answered 24/8, 2023 at 15:10 Comment(0)
A
0

I had both .npmrc and token in base64 and the correct configuration of .npmrc itself, but I still got this error It helped me to change the version of node.js, when I switched from v20 to v17 the error disappeared. I don't understand how this is related, but maybe it will help someone.

Aves answered 9/4 at 16:1 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewQuickwitted
T
0

in my case there was an outdated token in my .npmrc file so i pasted the new one and ran npm i and it worked

in terminal, i ran code ~/.npmrc and pasted the new .npmrc then npm i

Theorist answered 16/4 at 8:54 Comment(0)
P
0

you will have to exectute below command to fix npm ERR! code E401 in Mac system

rm -rf /Users/username/.npmrc 
npm login
npm i
Partee answered 21/4 at 8:23 Comment(0)
Z
0

Had the same issue when the company registry configured in .npmrc file as below.

registry=https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/npm/registry/

always-auth=true

In the command prompt, I have given my .npmrc file location and ran the command "vsts-npm-auth -config .npmrc -F" to get an Azure Artifacts token added to our user-level .npmrc file. This created new credentials for me and fixed my issue.

Zumstein answered 2/5 at 7:32 Comment(0)
D
0

I've tried everything that was suggested, but nothing worked. For me only worked one commend:

npm config set registry "https://registry.npmjs.com/"

Then command

npm install latest-version

Works with no error and all modules are installed.

Dipietro answered 4/5 at 13:1 Comment(0)
D
0

at least in my case it worked removing .npmrc from C:\Users[loginwindows] then run the command on admin powershell npm i -g vsts-npm-auth then run the command on admin powershell vsts-npm-auth -F -C .npmrc and that should have worked to solved the "ERR! code E401", now you could proceed to run npm run init on your project

Deodorize answered 18/5 at 3:26 Comment(0)
C
-3

Reinstall the lastest node.js. That fixed my issue.

Campanile answered 10/3, 2022 at 23:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.