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



My Node版本为10.15.0,NPM版本为6.8.4升级后运行npm安装时npm至14.16.0,npm至7.6.2

获取此错误-

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

  2. 如果这不起作用,请尝试删除$HOME目录中的.npmrc文件,如本文所述。

NPM错误代码E401:无法进行身份验证,需要:承载授权

注意-删除package-lock.json可能会有自己的问题,正如本文所提到的,所以除非你找到更好的解决方案,否则就使用这个解决方案。

删除`package-lock.json`以快速解决冲突

在目录C/Users/your-windows-username/

删除以下文件:

.cache
.package
.package-lock
.npmrc

之后,转到您的项目并在终端中运行以下命令

npm i

我在.npmrc中配置的公司注册表中出现了相同的错误

registry=https:<company-registry-url>

节点版本:19.1.0
NPM版本:8.19.3

解决方案:

执行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>.

在这个.npmrc用更新之后

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

.npmrc中的密码必须是base64编码的。只需复制粘贴密码就很容易出错,需要对其进行base64编码。

在运行npm run dev:后,我最近在各种项目上都遇到了同样的错误

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

对我来说,修复它的方法是删除我的package-lock.json文件(以及任何可能与npm产生冲突的yarn.lock文件(和node_modules目录。然后我用npm update更新了我的npm包。(注意:在更新任何npm包之前,您可能应该创建一个新的Git分支,并在该新分支中运行npm update。如果在更新后遇到更大的问题,则可以恢复到以前的分支。(

在我的包更新后,运行我的npm启动脚本(例如npm run dev(再次工作,没有出现错误。

注意:您可以运行npm outdated来查看哪些npm包可以使用更新。

查看指定的日志文件(例如/Users/xyz/.npm/_logs/2021-04-15T18_55_07_993Z-debug.log(。可能是要安装的第三方或公司软件包需要身份验证。

例如,如果您尝试安装FontAwesome的专业图标,但身份验证(令牌(丢失,则会发生此错误。

如果您配置了.npmrc,可能您的凭据已过期或需要新的凭据。试试这个vsts-npm-auth -config .npmrc。如果出现此错误[输入不是有效的Base-64字符串,因为它包含非Base-64字符、两个以上的填充字符或填充字符中的非法字符。]请尝试使用vsts-npm-auth -config .npmrc -force。这应该会生成新的凭据。

节点16.x.x也有同样的问题。我已经完成了这个主题和这里提到的主题的所有内容,但没有任何帮助!

帮助我登录的唯一一件事是,我已经删除了节点16.x.x,并且从这里安装了节点14.8.1-https://nodejs.org/en/download/releases/

这可能是因为npm上的一个错误。这发生在我的npm v7上。切换到v6并运行。

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

对我有用的是:

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

然后是CCD_ 17。已安装的所有依赖项

重新安装最新的node.js。这解决了我的问题。

最新更新