The ENEEDAUTH error occurs when npm cannot authenticate your machine to publish packages or access private registries. This happens when your authentication credentials are missing, expired, or misconfigured in your .npmrc file.
Fixes ENEEDAUTH
npm whoaminpm whoaminpm ERR! code ENEEDAUTHnpm ERR! need auth You need to authorize this machine using `npm adduser`
On this page
npm ERR! code ENEEDAUTH means npm requires authentication but cannot find valid credentials on your machine. This typically occurs when attempting to publish a package or access a private registry. The error indicates that npm cannot verify you have permission to perform the requested action.
Check if you're logged in:
npm whoamiIf this returns your username, you're logged in. If you get an ENEEDAUTH error, proceed to log in.
Authenticate with:
npm loginOr use npm adduser which works identically:
npm adduserAfter successful login, verify with npm whoami.
Check your .npmrc file at ~/.npmrc:
cat ~/.npmrcFor npm 9+, authentication tokens must use the scoped format:
//registry.npmjs.org/:_authToken=your-token-hereIf corrupted, delete it and re-login:
rm ~/.npmrc
npm loginIn GitHub Actions:
- name: Setup Node.js
uses: actions/setup-node@v3
with:
registry-url: 'https://registry.npmjs.org/'
node-version: '18'
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}If publishing a scoped package to a private registry:
npm login --scope=@myorg --registry=https://npm.pkg.github.com/NPM 9+ Breaking Changes: Node.js 18.14.0+ includes npm 9.3.1+, which enforces stricter .npmrc syntax. The old _auth field must now be scoped (e.g., //registry.npmjs.org/:_auth). Run npm config fix to auto-migrate deprecated configs. When using multiple registries, each scoped auth value must correspond to its registry URL.