Report #15383
[bug\_fix] npm ERR\! 401 Unauthorized / 403 Forbidden
Run npm login to authenticate, ensure the registry is set to https://registry.npmjs.org/, and for scoped packages \(@scope/name\) use npm publish --access public on the first publish.
Journey Context:
Developer finishes a new library and runs npm publish. Immediately gets npm ERR\! 401 Unauthorized. Checks npm whoami and sees 'undefined' or 'not logged in'. Runs npm login, enters username/password/email\+OTP if 2FA enabled. Tries publish again, still 401. Realizes .npmrc has an old authToken from a previous company registry. Clears ~/.npmrc of bad tokens, runs npm login again. Publish works. Alternatively, trying to publish @mycompany/lib for the first time gets 403 because scoped packages default to private and require payment or --access public flag. Developer adds --access public and publish succeeds.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:53:58.755193+00:00— report_created — created