简体   繁体   English

错误! 代码 E401 npm 错误! 密码不正确或丢失

[英]npm ERR! code E401 npm ERR! Incorrect or missing password

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我的节点版本是 10.15.0,NPM 版本是 6.8.4 在将 npm 升级到 14.16.0 并将 npm 升级到 7.6.2 后运行 npm install

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
  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.尝试在升级节点版本后运行命令“npm install”之前删除 package-lock.json 文件,如果您还没有这样做的话。

  2. If that will not work try removing the.npmrc file in $HOME directory as mentioned in this post.如果这不起作用,请尝试删除 $HOME 目录中的 .npmrc 文件,如本文所述。

NPM ERR Code E401: Unable to authenticate, need: Bearer authorization NPM ERR Code E401:无法认证,需要:承载授权

I had the same error with the company registry configured in .npmrc我在.npmrc中配置的公司注册表也有同样的错误

registry=https:<company-registry-url>

Node version: 19.1.0节点版本:19.1.0
NPM version: 8.19.3 NPM 版本:8.19.3

Solution:解决方案:

Execute npm login执行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在此.npmrc更新后

//<registry-url>/:_authToken=xxxxx

Your password in.npmrc must be base64 encoded.你在 .npmrc 中的密码必须是 base64 编码的。 Easy to screw up just copy-pasting the password, need to base64 encode that.只需复制粘贴密码即可轻松搞砸,需要对其进行 base64 编码。

In the directory C/Users/your-windows-username/在目录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之后,go 到您的项目并在您的终端中运行以下命令

npm i

Had the same issue with Node 16.xx I have done everything from this topic and those topics which were mentioned here and nothing helped me!与 Node 16.xx 有同样的问题我已经完成了这个主题和这里提到的那些主题的所有事情,但没有任何帮助!

The only thing that helped me to login was that I have deleted Node 16.xx and installed Node 14.8.1 from here - https://nodejs.org/en/download/releases/唯一帮助我登录的是我从这里删除了 Node 16.xx安装了 Node 14.8.1 - https://nodejs.org/en/download/releases/

I have been getting the same error recently on various projects after running npm run dev :在运行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.为我解决的问题是删除我的package-lock.json yarn.lock (以及任何可能与 npm 产生冲突的 yarn.lock 文件)和node_modules目录。 Then I updated my npm packages with npm update .然后我用npm update更新了我的 npm 包。 (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.) (注意:在更新任何 npm 软件包之前,您可能应该创建一个新的 Git 分支并在该新分支中运行npm update 。如果您在更新后遇到更大的问题,则可以恢复到以前的分支。)

After my packages were updated, then running my npm startup script (eg npm run dev ) worked again without errors.更新我的包后,运行我的 npm 启动脚本(例如npm run dev )再次运行而没有错误。

NOTE: You can run npm outdated to see which of your npm packages could use an update.注意:您可以运行已过期的npm outdated以查看您的哪些 npm 包可以使用更新。

It can be happening because of a bug on npm.它可能是由于 npm 上的错误而发生的。 This was happening to me with npm v7. npm v7 发生在我身上。 Switched to v6 and it worked.切换到 v6 并且它有效。

More context: https://github.com/npm/cli/pull/2153更多上下文: https ://github.com/npm/cli/pull/2153

Reinstall the lastest node.js.重新安装最新的 node.js。 That fixed my issue.这解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM