1

I experiencing an error when trying to publish an NPM package to Github Packages.
Firstly, I created a Personal Access Token ("PAT") with repo, write and read scopes.

The I added a .npmrc file to my project with the following text: //npm.pkg.github.com/:_authToken=ghp_6O8Ho[rest-of-token]

The, at the bash prompt, I entered the following (where myaccountname is the name of my Github account):
npm login --scope=@myaccountname --auth-type=legacy --registry=https://npm.pkg.github.com

I entered my username next.
Then, for the password, I pasted my PAT. Then, for the email, I entered the primary email address for my account and it seemed to succeed:
Logged in as myaccountname on https://npm.pkg.github.com/.

However, when I entered npm publish, I got the following error:

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in.
npm ERR! need auth You need to authorize this machine using npm adduser

Then running npm add user gave me a raft of whole new errors. But I cannot see that beinbg the right way to go anyway, as the Github doco does not mention that at all. It basically stops at npm publish, suggesting that it should have worked.

Oh and the repository url (https) is specified as the repository in package.json.

Can anyone see what I am missing?

onefootswill
  • 3,707
  • 6
  • 47
  • 101
  • Did you try setting [`publishConfig.registry`](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#publishing-a-package-using-publishconfig-in-the-packagejson-file)? Also, make sure that the name in package.json is scoped to your GH username – grimsteel Mar 21 '23 at 03:06
  • Your 2 suggestions appear to have worked. Just need to verify by consuming it now. Thanks. – onefootswill Mar 23 '23 at 09:25

0 Answers0