Getting error: "You must be logged in. Use `npm login` and try again." when trying to publish with NP

300 Views Asked by At

I have a classic js package that I created and I added NP to manage the publishment flow, but for some reason when I execute npm run np command, I'm getting the following error:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://registry.yarnpkg.com
npm ERR! need auth You need to authorize this machine using `npm adduser`

But I'm already signed in and if I execute npm publish it works perfectly

2

There are 2 best solutions below

0
Neosoulink On BEST ANSWER

I managed to solve my issue.

I removed np from my dependencies list and installed it globally

Then with any package manager I used, it worked fine.

Here's what my package.json script looks like:

// ...
"scripts": {
  "release": "npm run prepare && np"
}
# whit yarn
yarn run release

# whit npm
npm run release

# whit pnpm
pnpm run release
1
Jamon Holmgren On

This won't help the original poster, but for anyone else who stumbles across this and is using yarn to kick off the np script, try using npm run instead. This was the problem I had and using npm run fixed it.

So, for example:

# not this
yarn release

# but this instead
npm run release

(Assuming your release script is called release.)