60

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
user15650989
  • 727
  • 2
  • 5
  • 8
  • 1
    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. – MikhailRatner Jun 29 '22 at 09:33

11 Answers11

63
  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

paraS elixiR
  • 1,866
  • 1
  • 18
  • 26
  • 2
    Yep I totally missed that. Removing the package-lock.json worked for me. Thanks! – user15650989 Apr 15 '21 at 19:15
  • 3
    See [this SO answer](https://stackoverflow.com/questions/54124033/deleting-package-lock-json-to-resolve-conflicts-quickly#54127283) for potential reasons why you may not want to delete `package-lock.json`. – derekbaker783 Dec 13 '21 at 15:13
  • 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. – MikhailRatner Jun 29 '22 at 09:35
  • Can you explain what's causing the issue in the first place? – Slava Fomin II Jun 19 '23 at 18:32
11

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
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
jay
  • 257
  • 3
  • 5
9

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
jfk
  • 4,335
  • 34
  • 27
3

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

Andrey
  • 1,752
  • 18
  • 17
2

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.

Samuel Earl
  • 351
  • 4
  • 10
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.

davsto
  • 442
  • 5
  • 11
  • This actually helped me and turned out to be my exact problem (hadn't copied the .npmrc file over) so thank you! – DibsyJr May 10 '23 at 09:45
1

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.

tangel
  • 309
  • 1
  • 3
  • 12
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/

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

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

-3

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

JEuvin
  • 866
  • 1
  • 12
  • 31