NPM login 的时候出错,无法登录,解决

问题

今天想创建一个 npm 包,结果在登录的时候始终无法登录。
错误提示如下

PS E:\github\calculator-advanced> npm login
npm notice Log in on https://mirrors.cloud.tencent.com/npm/
Username: bingxinke
Password:
Email: (this IS public) kylebing@
npm ERR! code E409
npm ERR! 409 Conflict - PUT https://mirrors.cloud.tencent.com/npm/-/user/org.couchdb.user:bingxinke - user registration disabled

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Administrator\AppData\Local\npm-cache\_logs\2022-03-15T02_11_31_959Z-debug-0.log

原因

应该是你设置过 npm 的源地址,淘宝的或腾讯的,不再是原始的 npm 官方地址
所以登录的时候就无法登录了
一个简单的方法设置 npm 源,使用 nrm

nrm 是一个管理 npm 镜像地址的工具,可以通过它来改变 npm 镜像源地址

1. 安装 nrm

sh-3.2# npm i -g nrm
npm WARN deprecated coffee-script@1.7.1: CoffeeScript on NPM has moved to "coffeescript" (no hyphen)
/usr/local/bin/nrm -> /usr/local/lib/node_modules/nrm/cli.js
+ nrm@1.1.0
added 324 packages from 564 contributors in 22.77s

2. 查看可用的 npm 源地址

sh-3.2# nrm ls

* npm ---- https://registry.npmjs.org/
cnpm --- http://r.cnpmjs.org/
taobao - https://registry.npm.taobao.org/
nj ----- https:///
npmMirror https://skimdb.npmjs.com/registry/
edunpm - http:///

3.设置 npm 地址

将 npm 地址设置成官方源地址即可

λ nrm use npm
Registry has been set to: https://registry.npmjs.org/

结果

设置完成之后就能正常登录了,这里我已经设置了 2FA 两步验证。官方说明: ​​https://docs.npmjs.com/configuring-two-factor-authentication​​​NPM login 的时候出错,无法登录,解决_源地址