Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Node.js, PHP and APIs

npm publish fails in GitHub Actions with ENEEDAUTH

Errornpm error code ENEEDAUTH

Short 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.

  • Applies to npm 11.5.1+, Node.js 22.14+, GitHub Actions
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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/workflows
  2. 2Match what you see, then jump to its fix

    1. 1ENEEDAUTH although id-token: write is setThe workflow file name or repository does not match npmjs.comFix
    2. 2The workflow has no permissions block, or id-token: write is only in the callerThe job may not request an OIDC tokenFix
    3. 3The 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. 4No trusted publisher is configured and no NODE_AUTH_TOKEN reaches npmYou publish with a token, but setup-node has no registry-urlFix

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.json

2Fix

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 publish

Confirmed by docs.npmjs.com

Did this fix it?

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.yml

2Fix

Grant the permission on the publishing job.

permissions:
  id-token: write
  contents: read

3Verify

The publish step starts without ENEEDAUTH.

npm publish

Confirmed by docs.npmjs.com

Did this fix it?

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 --version

2Fix

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 publish

Confirmed by docs.npmjs.com

Did this fix it?

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/*.yml

2Fix

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 publish

Confirmed by github.com

Did this fix it?

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

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 fix

Back 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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.