直接使用npm publish报错:
npm error code E403
npm error 403 403 Forbidden - PUT https://registry.npmjs.org/xxxx - Two-factor authentication or granular access token with bypass 2fa enabled is required to publish packages.
npm error 403 In most cases, you or one of your dependencies are requesting
npm error 403 a package version that is forbidden by your security policy, or
npm error 403 on a server you do not have access to.
大概意思是从2026年开始,必须使用2FA发布package
但是在实际开启2FA的过程中,发现只有这一种方式
后续会弹出安全中心的2种验证方式,使用手机的Authenticator App无论我怎么扫描二维码,都无法完成npm的2FA验证。
我使用的是Window PC设备,所以没有PIN码之类的安全选项,简单说就是我这个设备环境是无法完成2FA验证的。
解决办法
npm生成一个token,使用这个token发布package
记得勾选绕过2FA验证,token最长只有90天,眼下暂时能解决问题。
之后在命令行中设置这个token
npm config set //registry.npmjs.org/:_authToken=xxxx
执行npm publish成功!