npm publish fails in GitHub Actions with ENEEDAUTH
npm error code ENEEDAUTHShort answer
ENEEDAUTH means npm has no valid login in the job. With npm trusted publishing the usual causes are a workflow file name that differs from the one saved on npmjs.com, a missing id-token: write permission, or a self-hosted runner. With a classic token, the token must reach npm through setup-node.
Fix it fast
1Find out which cause you have
Print the pieces trusted publishing depends on: the npm and Node versions in the job, and the workflow file names in the repo (npmjs.com must hold one of them exactly).
node --version npm --version ls .github/workflows2Match what you see, then jump to its fix
- 1
ENEEDAUTH although id-token: write is setThe workflow file name or repository does not match npmjs.comFix - 2
The workflow has no permissions block, or id-token: write is only in the callerThe job may not request an OIDC tokenFix - 3
The job runs on runs-on: self-hosted, or node --version is below 22.14, or npm below 11.5.1A self-hosted runner, or npm and Node that are too oldFix - 4
No trusted publisher is configured and no NODE_AUTH_TOKEN reaches npmYou publish with a token, but setup-node has no registry-urlFix
- 1
What does the error look like?
npm error code ENEEDAUTH
Cause 1 of 4
The workflow file name or repository does not match npmjs.com
1Check
npm does not verify the trusted publisher settings when you save them, so a mistake shows up only at publish time. The filename must include the extension, for example publish.yml, and package.json repository.url must exactly match the GitHub repository.
ls .github/workflows
grep -n -A3 '"repository"' package.json2Fix
Make the filename on npmjs.com identical to the file in .github/workflows, and fix repository.url (a forked repo often still points at the original).
"repository": {
"type": "git",
"url": "git+https://github.com/OWNER/REPO.git"
}3Verify
Re-run the publish job.
npm publishConfirmed by docs.npmjs.com
Cause 2 of 4
The job may not request an OIDC token
1Check
Trusted publishing needs id-token: write. If the workflow is a reusable one (workflow_call) or started manually, the permission must be set in both the parent and the child workflow.
grep -n -A3 permissions .github/workflows/publish.yml2Fix
Grant the permission on the publishing job.
permissions:
id-token: write
contents: read3Verify
The publish step starts without ENEEDAUTH.
npm publishConfirmed by docs.npmjs.com
Cause 3 of 4
A self-hosted runner, or npm and Node that are too old
1Check
Trusted publishing works only on GitHub-hosted runners and needs npm CLI 11.5.1 or later with Node 22.14.0 or higher.
node --version
npm --version2Fix
Run the job on a GitHub-hosted runner and set up a current Node version before publishing.
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v4
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'3Verify
Print the versions in the job, then publish.
node --version && npm --version
npm publishConfirmed by docs.npmjs.com
Cause 4 of 4
You publish with a token, but setup-node has no registry-url
1Check
setup-node writes a project .npmrc with the registry and reads the token from the NODE_AUTH_TOKEN environment variable. Without registry-url that file is not written.
grep -n -B2 -A4 setup-node .github/workflows/*.yml2Fix
Set registry-url in setup-node and pass the token as NODE_AUTH_TOKEN on the publish step.
- uses: actions/setup-node@v4
with:
node-version: '24'
registry-url: 'https://registry.npmjs.org'
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}3Verify
Re-run the job; the publish step no longer stops with ENEEDAUTH.
npm publishConfirmed by github.com
How do I stop it coming back?
- Prefer trusted publishing over long-lived tokens where the package supports it.
- Name the publish workflow once and never rename it without updating npmjs.com.
- A new trusted publisher config must finish a first successful publish within 2 days, so test it right after you save it.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
npm says it failed to replace ${NPM_TOKEN} in the config
npm error Failed to replace env in config: ${NPM_TOKEN}
npm replaces ${NPM_TOKEN} in .npmrc with the value of an environment variable of that name when it starts.
3 causes, each with a fixBack end
ng serve says it cannot determine the project or target
Cannot determine project for command.
The Angular CLI looked through angular.json for a project that defines the target you asked for (serve, build, test) and found none, or found several and could not pick one.
3 causes, each with a fixBack end
ng fails with Cannot find module @angular/cli/bin/ng
Cannot find module '@angular/cli/bin/ng'
The ng command is the entry point to the Angular CLI package.
2 causes, each with a fixBack end
Angular app shows 'Cannot GET /' when served by a Node.js server
Cannot GET /dashboard
Cannot GET / is Express saying no route or file matches the request.
3 causes, each with a fixBack end
ng serve cannot find the dev-server builder package
Could not find the implementation for builder @angular/build:dev-server
The builder named in angular.json (for example @angular-devkit/build-angular:dev-server) is looked up as an npm package starting from the workspace root.
3 causes, each with a fixBack end
Angular build says it cannot resolve '@angular/localize/init'
Can't resolve '@angular/localize/init' in '/usr/src/app/src'
The build imports @angular/localize, and that package is not in node_modules.
2 causes, each with a fix