无法登录 GitHub 程序包注册表

Unable to login to GitHub Package Registry

我正在尝试通过 GitHub 包注册表发布 npm 包,我正在关注文档,当我在输入 usernamepassword 后尝试使用以下命令登录时(即使两者都是正确的),我总是低于错误。

// Step 2: Authenticate
$ npm login --registry=https://npm.pkg.github.com/

错误日志:

npm login --registry=https://npm.pkg.github.com/
Username: ***********
Password:
Email: (this IS public) *****************
npm ERR! code E401
npm ERR! Registry returned 401 for PUT on https://npm.pkg.github.com/-/user/org.couchdb.user:kgangadhar: Error authenticating user: Bad credentials

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\karth\AppData\Roaming\npm-cache\_logs19-10-31T05_35_05_829Z-debug.log

有人知道怎么解决吗?

您的 GitHub 帐户是否启用了双因素身份验证?如果是这样,请尝试创建个人访问令牌并使用它代替密码。这里有instructions to create a token.

更新:Github now requires personal access tokens for all accounts, regardless of if you have 2fa enabled

本文引用了您正在执行的相同命令,之前的答案是正确的。只是留下这个来加强它:

Link to Github configuration page

只有 Ctrl + F 在搜索 npm login --registry=https://npm.pkg.github.com

我 运行 遇到了同样的问题,因为我试图使用我的 Github 密码登录,而实际上 你需要使用 Github Personal Access Token 作为密码.

Username: YOUR_GITHUB_USERNAME  
Password: YOUR_GITHUB_PERSONAL_ACCESS_TOKEN  
Email: YOUR_EMAIL