Visovan Mihai
Visovan Mihai

Reputation: 435

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

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

Upvotes: 7

Views: 22479

Answers (2)

Visovan Mihai
Visovan Mihai

Reputation: 435

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>    

                  

Upvotes: -1

Neha Soni
Neha Soni

Reputation: 4694

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

Upvotes: 2

Related Questions