Rafal Cypcer
Rafal Cypcer

Reputation: 597

Migration of npm config between npm v8 and npm v9

I migrated from node 16.19.1 with npm version of 8.19.1 into node 20.5.1 with npm version 9.8.0 in my github actions workflows which publishes npm into Nexus repository with version OSS 3.41.1.

My initial config for npm v8.19.1 was as below:

npm config set registry="http://nexus.example.com:8081/nexus/repository/example-package/"
npm config set _auth="MY_BASE_64_TOKEN"
npm config set email="[email protected]"
npm config set always-auth=true
npm config set strict-ssl=false

And with this config I could successfully execute npm publish

npm v9 introduced breaking changes which affected my config, for example:

So I changed my config to:

npm config set email="[email protected]"
npm config set strict-ssl=false
npm config set auth-type=legacy
npm config set registry="http://nexus.example.com:8081/nexus/repository/example-package/"
npm config set //nexus.example.com:8081/nexus/repository/example-package/:_auth=MY_BASE_64_TOKEN

and after npm publish I have those errors:

npm verb Linux 5.15.0-1041-azure
npm verb node v20.5.1
npm verb npm  v9.8.0
npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm verb exit 1
npm verb code 1

Do you know what I'm doing wrong or what I'm missing?

Upvotes: 2

Views: 2159

Answers (1)

Luca Oddone
Luca Oddone

Reputation: 61

Hello
as you noticed npm v9 introduced breaking changes. I encountered your same issues on my GitLab CI environment but I managed to overcome them by implementing the steps described below.
Before showing the steps that I followed, I would like to stress out that the identified solution is based on authentication using basic auth, plus it has been tested for the systems and platforms illustrated below:

  • node:18.18.0 Docker image
  • Sonatype Nexus Repository OSS 3.59.0-01
  • npm v9.8.1

Referring to your parameters, the steps to be implemented are reported below:

  • echo "[email protected]" > /root/.npmrc
  • echo "always-auth=true" > /root/.npmrc
  • echo "//nexus.example.com:8081/nexus/repository/_auth=<username:password>" > /root/.npmrc
  • npm publish --registry=http://nexus.example.com:8081/nexus/repository/example-package/

Watch out! As stated by the official documentation, <username:password> value must be expressed as base64-encoding.

Finally, I actually see that you are accessing the registry via HTTP and not via HTTPS, consequently I imagine that in your case you need the additional step:

  • echo "strict-ssl=false" > /root/.npmrc

Even though, I am not quite sure about it, since in my case, my company's registry was exposed via HTTPS.

Upvotes: 3

Related Questions