- Use Node.js v24. Trusted Publishing does not work on earlier versions of Node.js.
- Go to "Account > Access Tokens" and click "Generate Access Token".
- Give the new token "read and write" persmissions to "All packages".
- If you have 2FA enabled on npm (which you should), check the "Bypass 2FA" checkbox neatly hidden in the UI. Otherwise, npm will fail with an error demanding an OTP during automatic publishing.
- Create the token.
- Add it as a secret in your GitHub repo.
- Provide it to your release automation tooling.
- In your
package.jsonmake sure to setpublishConfig.accessto"public". - (Optional) In your
package.jsonmake sure to setrepository.urlto the HTTPS URL of your repository. This is only needed if you're planning on using provenance. - In your publishing action, make sure to set
permissions.id-tokentowriteon the job level. This is required for Trusted publishing.
jobs:
publish:
permissions:
id-token: write- In
actions/setup-node, make sure to setalways-authandregistry-url. Without these, npm will think you are running a tokenless flow and will fail since trusted publishing isn't configured for your package since to configure it you need to publish the package in the first place.
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 24
always-auth: true
registry-url: 'https://registry.npmjs.org'- Publish the first version of the package.
- Delete the generated access token from NPM.
- Delete the npm token secret from GitHub.
- Delete the
always-authandregistry-urlfrom theactions/setup-nodeaction in your publishing workflow. If you don't, npm will try authenticating and will fail with 404 meaning 403, meaning it thinks you want a token-based workflow. - Go to your package on npmjs.com, then "Settings".
- In the "Trusted Publisher" section, fill in your GitHub username/org and the repo name. Fill in the GitHub actions workflow name. Watch out for typos.
- Apply changes.
- In the same package settings, go to the "Publishing access" and set it to require 2FA.
- Apply changes.
- Enjoy life.
Wow, all these steps for every single package I want to publish? Darn...๐