Skip to content
Latchkey

npm publish "ENEEDAUTH ... need auth ... run npm login" in CI

npm could not find any credentials for the target registry, so it refused to publish before even contacting it. The runner has no logged-in session by default; you must supply an auth token.

What this error means

npm publish fails with "npm ERR! code ENEEDAUTH", "npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/", and "npm ERR! need auth You need to authorize this machine using npm adduser".

npm
npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.npmjs.org/ (under a "publish" account)
npm ERR! need auth You need to authorize this machine using `npm adduser`

Common causes

No token configured for the registry on the runner

CI containers start with no npm login. Without a _authToken in .npmrc or NODE_AUTH_TOKEN, npm has no credentials to send.

The token is set but not for the registry being published to

A token configured for the default registry does not apply to a custom or scoped registry URL, so that publish still has no auth.

How to fix it

Provide the token via setup-node and NODE_AUTH_TOKEN

setup-node writes an .npmrc that reads NODE_AUTH_TOKEN; pass the secret in the publish step env.

.github/workflows/release.yml
- uses: actions/setup-node@v4
  with:
    node-version: 20
    registry-url: 'https://registry.npmjs.org'
- run: npm publish
  env:
    NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

Write the token into .npmrc explicitly

For a custom registry, set the per-registry auth token line so npm finds credentials for that exact host.

Terminal
echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> ~/.npmrc
npm publish

How to prevent it

  • Always pass a publish token via NODE_AUTH_TOKEN or a per-registry .npmrc line.
  • Match the auth token to the exact registry URL you publish to.
  • Keep tokens in CI secrets, never committed to the repo .npmrc.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →