NPM Publish error: You need to authorize this machine using npm adduser
Asked Answered
D

2

6

I am trying to run npm publish on a package after I've upgraded to node v18 and npm v9.

But I get the following error:

This command requires you to be logged in to https://some-package.com:48082/nexus/repository/path1/
You need to authorize this machine using npm adduser

My user .npmrc file:

//some-package.com:48082/nexus/repository/:keyfile=/Users/<host>/Documents/Certificates/npm.key.pem.   
//some-package.com:48082/nexus/repository/:certfile=/Users/<host>/Documents/Certificates/npm.crt.pem
//registry.npmjs.org/:_authToken=<auth_token>

My project .npmrc file:

 @fortawesome:registry=https://npm.fontawesome.com/.  
 @scope1:registry=https://some-package.com:48082/nexus/repository/path1/   
 @scope2:registry=https://some-package.com:48082/nexus/repository/path2/  
 //npm.fontawesome.com/:_authToken=<auth_token>   
 //some-package.com:48082/nexus/repository/:_auth=<auth>   
 strict-ssl=false
Diversion answered 28/2, 2023 at 11:40 Comment(4)
To publish an NPM package via CLI, you need to log in first. I assume you already created an account on the npm registry, so just log in with that username and password and it will work.Older
I tried to login, I've recevied the OTP code via email, entered it but without results.Diversion
If I run npm whoami, I get the username I've created, so I'm assuming I'm logged in.Diversion
I added a few useful commands, as I cannot post those as comments. Please check if it helps.Older
O
2

To publish a package to NPM you need to login to the NPM registry. Here are a few steps to do that-

Login to NPM

  • If you are not registered
npm adduser
  • If you are already registered
npm login
  • If you are already logged in and want to verify the user
npm whoami

Build and publish

  • Create a build
npm run build-library
  • Publish to NPM
npm publish --access public
Older answered 28/2, 2023 at 11:50 Comment(11)
So after I ran npm whoami, I get my username. It means the login is successful. But after I run npm publish, I get the same error with npm adduser.Diversion
Did you try the last command, npm publish --access publicOlder
Yes, with the same result. What I'm seeing in the error is that is not refering to the registry.npmjs.org, but to the nexus repository we use as a wrapper to the registry.npmjs.org. So do I also need to be logged in on nexus or something?Diversion
See this answer, if it helps- https://mcmap.net/q/352877/-authentication-error-on-publishing-to-private-npm-repository-on-nexus/11834856Older
Seems like you are trying to publish the package privately. Is it?Older
Yes! I'm looking now on the stackoverflow question you sent.Diversion
If I try to add an user on the private registry, I get web login is not supported. npm adduser --registry=https://some-package.com:48082/nexus/repository/path1/Diversion
Give it a read- docs.npmjs.com/creating-and-publishing-private-packagesOlder
On it, I need to understand more of this scopes, registried, auth stuff. I will come back if I found anything. Thanks!Diversion
Where can I find my user name to insert in npm adduser?Nystatin
If you already have an account created, this command will ask for your existing username, otherwise, you can create a new user with this same command. To verify if you are already logged in, run npm whoami. For more information, read this- medium.com/easy-coding/…Older
D
-1

The fix for this issue is that we need to add the certificate and key files in the global .npmrc on repo level, not on the nexus level:

//some-package.com:48082/nexus/repository/path1/:keyfile=/Users/<host>/Documents/Certificates/npm.key.pem   
//some-package.com:48082/nexus/repository/path1/:certfile=/Users/<host>/Documents/Certificates/npm.crt.pem
//some-package.com:48082/nexus/repository/path2/:keyfile=/Users/<host>/Documents/Certificates/npm.key.pem   
//some-package.com:48082/nexus/repository/path2/:certfile=/Users/<host>/Documents/Certificates/npm.crt.pem

Same for the project .npmrc:

//some-package.com:48082/nexus/repository/path1/:_auth=<auth>                        
//some-package.com:48082/nexus/repository/path2/:_auth=<auth>    

                  
Diversion answered 28/2, 2023 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.