錯誤現象
執行 npm publish 命令發佈包時,遇到以下錯誤
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包時,必須使用以下驗證方式:
- 雙因素認證(2FA) :已啓用2FA的賬號,發佈時需輸入動態驗證碼
解決辦法
- 登錄 npm官網http://www.npmjs.com/
- 進入 Account Settings → Security
- 啓用 Two-Factor Authentication
- 完成設置
- 執行發佈命令: npm publish
- 輸入Authenticator應用生成的驗證碼
- 發佈成功