Today I finally got npm's Trusted Publishing (OIDC) working for my cursor-history package. It was a frustrating few hours, but I learned a lot. Here's my debugging diary.
What I Wanted
I wanted to publish my npm package without storing an NPM_TOKEN secret in GitHub. npm now supports "Trusted Publishing" using OIDC (OpenID Connect) - GitHub Actions can prove its identity to npm, and npm trusts packages published from verified workflows. No token management, no secret rotation. Sounds perfect.
Step 1: Setting Up Trusted Publishing on npm
I configured npm to trust my GitHub repo:
- Went to npmjs.com β my package β Settings β "Trusted Publishing"
- Added my repo
S2thend/cursor-historywith workflownpm-publish.yml
Then I updated my GitHub workflow:
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write # Required for OIDC
steps:
# ... build steps ...
- name: Publish to NPM
run: npm publish --provenance --access public
I removed the NODE_AUTH_TOKEN env var since I thought OIDC would handle everything.
Step 2: The First Error
Pushed a tag, watched the CI... and it failed:
npm notice publish Signed provenance statement with source and build information from GitHub Actions
npm notice publish Provenance statement published to transparency log
npm notice Access token expired or revoked. Please try logging in again.
npm error code E404
npm error 404 Not Found - PUT https://registry.npmjs.org/cursor-history - Not found
Wait, what? The provenance signing worked (I could see it in the Sigstore transparency log), but then it complained about a token? And why E404 for a package that definitely exists?
Step 3: My Wrong Assumption
I was confused. I thought maybe I still needed the NPM_TOKEN. So I added it back:
- name: Publish to NPM
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
But wait - I wanted to use OIDC precisely to avoid tokens! This felt wrong.
Step 4: Getting the Right Insight
After some research, I found the crucial insight:
"The workflow is still picking up an npm auth token (or an authToken config), and npm is attempting token auth instead of the OIDC trusted publisher flow. When token auth fails, npm often surfaces it as a 404."
This made sense! npm was trying to use a stale or invalid token instead of OIDC. The E404 wasn't "package not found" - it was npm's weird way of saying "authentication failed."
π‘ Tip: npm's E404 error during publish often means authentication failure, not that the package doesn't exist!
Step 5: The Investigation
I checked for things that might force token auth:
.npmrcfile in repo? No, didn't have one.- Workflow filename matches npm config? Yes, exactly
.github/workflows/npm-publish.yml. - Could
actions/setup-nodebe creating an.npmrc? Bingo!
The actions/setup-node action with registry-url set actually creates an .npmrc file. This might configure token auth by default, hijacking the OIDC flow.
Step 6: The Fix
Two changes fixed everything:
6.1 Upgrade to Node 24
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24' # Was '20'
registry-url: 'https://registry.npmjs.org'
Node 24 ships with npm 11, which has better OIDC/Trusted Publishing support. Several people reported that upgrading to Node 24 fixed their "weird 404/auth" issues.
π Note: Node 20 uses older npm versions that have known issues with Trusted Publishing. Upgrading to Node 24 (npm 11) is the recommended fix.
6.2 Force OIDC by Clearing Token Config
- name: Force OIDC (clear any token config)
run: |
rm -f .npmrc ~/.npmrc || true
npm config delete //registry.npmjs.org/:_authToken || true
- name: Publish to NPM
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ""
NPM_TOKEN: ""
This ensures:
- Any
.npmrcfiles (created by setup-node or elsewhere) are removed - Any authToken config is deleted
- Environment variables that might trigger token auth are explicitly empty
Step 7: Success!
After these changes, the publish worked perfectly:
npm notice Publishing to https://registry.npmjs.org/ with tag latest and public access
npm notice Signed provenance statement with source and build information from GitHub Actions
npm notice Provenance statement published to transparency log
+ cursor-history@0.10.0
No tokens. No secrets. Just OIDC magic.
Key Lessons Learned
-
OIDC provenance signing β OIDC authentication: The
--provenanceflag signs your package with an OIDC attestation (proves it came from your repo). But npm also needs to authenticate the publish action itself - and that's where Trusted Publishing comes in. They're related but separate. -
npm's E404 often means auth failure: Don't be fooled by "Not Found" - it can mean "you're not authorized."
-
Token auth takes precedence: If npm finds ANY token config (
.npmrc, env vars), it'll try token auth first. You need to actively clear these to force OIDC. -
Node version matters: Node 24 / npm 11 has the most reliable Trusted Publishing support. If you're on Node 20, consider upgrading for CI.
-
actions/setup-nodecreates config: When you setregistry-url, it creates an.npmrc. This might interfere with OIDC if there's any token-related config.
β οΈ Warning: Don't mix token auth and OIDC! If you want Trusted Publishing, make sure to clear all token configurations.
Final Working Workflow
Here's my complete working workflow for OIDC publishing:
name: Publish to NPM
on:
push:
tags:
- 'v*'
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- name: Show versions
run: node -v && npm -v
- run: npm ci
- run: npm run build
- run: npm test
- name: Force OIDC (clear any token config)
run: |
rm -f .npmrc ~/.npmrc || true
npm config delete //registry.npmjs.org/:_authToken || true
- name: Publish to NPM
run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ""
NPM_TOKEN: ""
Hope this helps someone else struggling with the same cryptic errors!
Appendix
- npm Trusted Publishing docs: https://docs.npmjs.com/generating-provenance-statements
- GitHub Actions OIDC: https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect
- Sigstore transparency log: https://search.sigstore.dev/