Unable to publish to an NPM Registry (local)

Solution 1:

As it turns out, I did not have the Npm Bearer Token Realm in my list of active realms. Once I moved it to Active, the publish completed successfully!

enter image description here

Solution 2:

Additonally to @EdH's answer we discovered that the format of .npmrc has changed so base64 encoded _auth will not work anymore... and the token has to be created by logging into the repo.

old .npmrc

registry=https://host/repo
_auth=12afdjsljl123213

new .npmrc

//host/repo/:_authtoken=uuidOfToken

Solution 3:

Additionally to @Daniel's answer, I discovered that when adding user credentials/logging into npm, you can't have a trailing slash on the registry url.

Bad:

npm adduser --registry=https://repo.localhost/repository/npm-internal/

Good:

npm adduser --registry=https://repo/repository/npm-internal

Also, if you're looking to automate the login (i.e. non-interactively), I used a good tool called npm-cli-login.

npm-cli-login -u admin -p admin123 -e [email protected] -r https://repo/repository/npm-internal

Solution 4:

I realize that this post is a couple years old now, but as of struggling with this issue for many hours, I finally found what worked for me that I've not seen in many other places. The problem was that I was not specifying the _authToken within the .npmrc file. Adding this as shown below resolved the issue and I was able to successfully run npm commands without a 401 error.

.npmrc

registry=https://test.repo.com/repository/npm-group/
//test.repo.com/repository/npm-group/:_authToken=NpmToken.${NPM_TOKEN}