Can't publish to npmjs using Yarn in GH Actions with OIDC #188565
-
BodyI have a package on npmjs.com, and am trying to publish a security update. On npmjs.com I've set up the Trusted Publisher settings to be GitHub Actions, arad1el/[my-repo-name], and the workflow name is the filename (npm-publish.yml) I adapted my previous workflow file to closer match npm's example - the key difference is that I use yarn rather than npm `name: Publish to npmjs on: jobs: The workflow falls over when it gets to the "yarn publish --provenance" command saying that it "error Couldn't publish package: "https://registry.npmjs.org/[package-name]: Not found" The package definitely exists, so it must be something to do with my setup. How can I properly configure this? Guidelines
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
|
Full Example Workflow on: jobs: |
Beta Was this translation helpful? Give feedback.
-
|
The error: Couldn't publish package: https://registry.npmjs.org/[package-name]: Not found usually means this is an authentication issue, not that the package actually doesn’t exist. When using OIDC Trusted Publishing, you should not rely on traditional auth tokens — but you still need to make sure your workflow and npm config are aligned properly. A few things to check:
In package.json: The name must match the one on npm (including scope, if any). If it’s scoped (e.g. @user/package), ensure the scope matches what’s published. Even a small mismatch will cause a 404.
With OIDC, you don’t need NODE_AUTH_TOKEN, but you must:
You already have this — that’s good. But make sure: The workflow filename exactly matches what you configured in npm Trusted Publisher. The repo name in npm settings matches exactly (arad1el/[my-repo-name]). OIDC is very strict about exact matches.
If your package is scoped, add this to package.json: "publishConfig": { Otherwise npm may reject the publish attempt.
--provenance relies on npm CLI under the hood. Sometimes Yarn doesn’t fully align with npm’s OIDC flow. If everything else looks correct, try temporarily replacing: yarn publish --provenance with: npm publish --provenance after running yarn build. If that works, the issue is Yarn’s publish handling with OIDC.
Your workflow runs on: on: Make sure you're creating a GitHub Release (not just pushing a tag). OIDC validation checks the workflow context carefully. |
Beta Was this translation helpful? Give feedback.
-
|
This is a common "teething issue" with the transition to OIDC (Trusted Publishing) on npm, specifically when using Yarn v1 (Classic). The "Not Found" error is actually a misleading response from the npm registry when authentication fails—in this case, because Yarn v1 does not natively support the OIDC/Provenance handshake required by the new Trusted Publisher flow. Here is the professional breakdown and the fix to get your security update published.
Update your npm-publish.yml to this structure: YAML jobs:
Case Sensitivity: In your npmjs.com Trusted Publisher settings, the Organization/User and Repository names must match the casing in your GitHub URL exactly (e.g., Arad1el vs arad1el). Workflow Filename: Ensure the filename in the npm settings is exactly npm-publish.yml. Even a capital letter or a missing .yml extension will cause the OIDC handshake to fail. Package.json Repository: Ensure your package.json has a repository field that matches the repo you are publishing from: JSON |
Beta Was this translation helpful? Give feedback.
-
|
Thank you @MHassan-Tariq and @shivrajcodez for your explanations - I'm marking @MHassan-Tariq as the answer since it covered the same ground but also highlighted a small change in package.json which might have made the difference. It seems to be fully working now |
Beta Was this translation helpful? Give feedback.
This is a common "teething issue" with the transition to OIDC (Trusted Publishing) on npm, specifically when using Yarn v1 (Classic). The "Not Found" error is actually a misleading response from the npm registry when authentication fails—in this case, because Yarn v1 does not natively support the OIDC/Provenance handshake required by the new Trusted Publisher flow.
Here is the professional breakdown and the fix to get your security update published.
The Root Cause: Yarn v1 vs. OIDC
The yarn publish command in Yarn v1 (Classic) is built on an older architecture that doesn't know how to exchange a GitHub OIDC token for an npm session. When you run yarn publish --provenance, it fails to pr…