Home > Software engineering >  Lerna boostrap fails with npm ERR! code E401
Lerna boostrap fails with npm ERR! code E401

Time:07-01

whenever i'm running Lerna bootstrap on Jenkins its fails with error, but passes on local machine.

npm ERR! code E401
npm ERR! Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

Package.json on main folder

"scripts":{
  "bootstrap": "lerna bootstrap --loglevel verbose",
  "publish-packages": "lerna publish --skip-git",
  "clean": "lerna clean"
},
"dependencies": {
  "lerna": "^5.0.0"
}

lerna.json

{
  "packages": [
    "packages/*"
  ],
  "npmClientArgs": [
    "--strict-ssl=false",
    "--always-auth=true"
  ],
  "version": "independent"
}

running commands

npm i
npm run bootstrap

npm i - passes but "npm run bootstrap" fails.

I've tried multiple options like

  1. in .npmrc added credentials for my-repo

    //my-repo-url:8081/nexus/repository/npm-repo/:_password=##base-64-encoded-password## //my-repo-url:8081/nexus/repository/npm-repo/:username=##usernamr##

  2. in added in .npmrc _auth=##base-64-encoded-username-and-password##

  3. added or removed "--always-auth=true" & "--strict-ssl" from "npmClientArgs" in lerna.json

Versions

  1. node v14.17.0
  2. npm 6.14.13

CodePudding user response:

Option#1

  1. I resolved by, adding "_auth" in lerna.json -> npmClientArgs.I Copied _auth value from .npmrc and added in "npmClientArgs"
  2. You can also generate authToken and use it here
{
  "packages": [
    "packages/*"
  ],
  "npmClientArgs": [
    "--strict-ssl=false",
    "--always-auth=true",
    "--_auth=AUTH-KEY"
  ],
  "version": "independent"
}

Option#2

  1. During build, you can recursively copy .npmrc in all "packages/*" folder
  • Related