2

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
Visovan Mihai
  • 337
  • 5
  • 10
  • 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. – Neha Soni Feb 28 '23 at 11:44
  • I tried to login, I've recevied the OTP code via email, entered it but without results. – Visovan Mihai Feb 28 '23 at 11:45
  • If I run `npm whoami`, I get the username I've created, so I'm assuming I'm logged in. – Visovan Mihai Feb 28 '23 at 11:49
  • I added a few useful commands, as I cannot post those as comments. Please check if it helps. – Neha Soni Feb 28 '23 at 11:51

2 Answers2

1

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
Neha Soni
  • 3,935
  • 2
  • 10
  • 32
  • 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`. – Visovan Mihai Feb 28 '23 at 11:53
  • Did you try the last command, `npm publish --access public` – Neha Soni Feb 28 '23 at 11:54
  • 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? – Visovan Mihai Feb 28 '23 at 11:55
  • See this answer, if it helps- https://stackoverflow.com/q/57279087/11834856 – Neha Soni Feb 28 '23 at 11:57
  • 1
    Seems like you are trying to publish the package privately. Is it? – Neha Soni Feb 28 '23 at 11:59
  • Yes! I'm looking now on the stackoverflow question you sent. – Visovan Mihai Feb 28 '23 at 12:02
  • 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/` – Visovan Mihai Feb 28 '23 at 12:08
  • Give it a read- https://docs.npmjs.com/creating-and-publishing-private-packages – Neha Soni Feb 28 '23 at 12:10
  • 1
    On it, I need to understand more of this `scopes`, `registried`, `auth` stuff. I will come back if I found anything. Thanks! – Visovan Mihai Feb 28 '23 at 12:13
  • Where can I find my user name to insert in `npm adduser`? – ESI Apr 30 '23 at 08:49
  • 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- https://medium.com/easy-coding/convert-a-single-file-component-into-a-vue-library-and-publish-it-to-npm-b0f10f479a04 – Neha Soni May 01 '23 at 03:29
0

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>    

                  
Visovan Mihai
  • 337
  • 5
  • 10