Three gates before your first npm publish: 2FA, provenance, and staged releases
说明与用途
npm 包发布会遇到三道隐藏门:2FA、来源证明和 staged 发布。作者说明如何通过 CI 和受信任发布来绕过每一道门。
问题
Publishing a new npm package can fail at multiple hidden gates, causing confusion and delays.
结果
The developer successfully published the plugin, enabled provenance, and understood staged publishing mechanics, reducing future publish failures.
工作流
- 1. Run
npm whoamito verify token validity. - 2. If publishing a new name, use a direct publish token and run
npm publishinteractively. - 3. For provenance, add
"provenance": trueinpublishConfigand publish from CI with--provenanceandpermissions: id-token: write. - 4. Configure trusted publisher with
npm trust github my-package --file publish.yml --repo my-org/my-repo --allow-publish. - 5. For staged releases, use a stage‑only token and run
npm stage publishafter the first direct publish. - 6. After publishing, wait for propagation and verify with
curl https://registry.npmjs.org/my-package/0.1.0. - 7. Update dist‑tags if needed with
npm dist-tag add [email protected] latest.
证据
The account had 2FA set up with a security key, not a TOTP app.
Automatic provenance generation not supported for provider: null
Cannot publish "my-package": this token can only publish to a staging area, npm error and "my-package" does not exist yet.
- 记录日期: 2026-10-26T14:26:16.822Z