lerna: Lerna 401 error when publishing to a private repo

Expected Behavior

Runing using Jenkins :

lerna publish --yes --canary minor

Should publish my packages to the provided private registry.

Current Behavior

Throws error:

18:55:35 lerna notice Skipping all user and access validation due to third-party registry
18:55:35 lerna notice Make sure you're authenticated properly ¯\_(ツ)_/¯
18:55:35 lerna http fetch PUT 401  85ms
18:55:35 lerna ERR! E401 Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"

Possible Solution

I tried :

1/ in lerna.json

  "command": {
    "publish": {
      "npmClient": "npm",
      "verifyAccess": false,
      "ignoreChanges": []
    }
  }

2/ --no-verify-access

3/ add .npmrc (it is ignored).

Your Environment

Executable Version
lerna --version 3.19.0
npm --version 6.4.1
node --version 10.14.1

Any help please ?

How can I setup authentication using lerna ?

Is there equivalent to npm options --globalconfig ${pp.env.GLOBAL_NPM_CONFIG} --color=always and --userconfig ${pp.env.NPM_CONFIG} using lerna ?

thanks 😃

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 2
  • Comments: 29

Commits related to this issue

Most upvoted comments

@helabenkhalfallah, try this official GitHub guidelines.

My problem was caused by—

  1. local .npmrc, where I specified custom registry URL without my GitHub name, and
  2. Lerna package package.json files missed repository field. E.g., github:<your-github-name>/<your-repo>

Additional info for researchers. In a case when multiple packages are publishing from GitHub Actions, the YAML should provide env variables with tokens. I found a good example. With the 401 error, these lines helped me (from the example).

Many thanks to the repo author and to the authors of this thread 🙏🏻

I solved this problem in my monorepo by simply adding this snippet to my lerna.json file:

"command": {
  "publish": {
    "registry": "https://npm.pkg.github.com/"
  }
}

I was also stuck on this message

Screenshot

My problem was in package.json of the sub-packages i had to change private:true to false.

I got the error that told me what I was missing when I ran npm publish inside one of my packages. Maybe lerna could also be more explicit on their logs

@nifanic I tried both but I get error while publishing

image

For who is working with Github Actions, Lerna and Github Packages: I had a simple monorepo setup. My only package was example But when I tried to publish to GHP, it gaves me the following error:

lerna http fetch PUT 404 https://npm.pkg.github.com/@zorilla-software%2ftest 305ms
lerna ERR! E404 The expected resource was not found.

Why this? It was not clear in the docs, but when I added this snippet in my package.json of example:

"repository": {
  "type": "git",
  "url": "ssh://git@github.com:REPOSITORY_OWNER/REPOSITORY_NAME.git",
  "directory": "packages/example"
},
"publishConfig": {
  "registry": "https://npm.pkg.github.com"
}

It worked.

Hello, folks. It only works when you setup your package.json name field equal to your repo name. What is weird. I was with this 404 error. But when I change my repo name to example to match the name @myscope/example, it works. The problem is tha I want to publish several packages, that’s why I’m using Lerna at the first place LOL.

@kaushikwavhal, the repo is now public. Please check.

It seems this issue mixes up several problems:

  1. lerna seemingly not correctly authorizing against the given registry (Nexus Repository Manager, NXRM), resulting in status code 401.
    When using basic auth as described in the NXRM documentation, then this can be solved by using the –legacy-auth flag.
    When using token auth, the npm Bearer Token Realm needs to be activated in the NXRM and npm adduser (or equivalent yarn command) needs to be run to create a token in the NXRM, that can be used for publishing. There should be no need for any other flags.
    This should solve the original problem.

  2. A mix-up with the repository configuration for the github registry, resulting in status code 404. This got resolved already.

  3. A screenshot that seems to show that publishing was successful with a claim that there was an error. It’s not quite clear what that error is and which registry is used, although it references the author of the github problem comment.
    @abhijeetmane if there is still an open issue with this for you, I would suggest opening a new issue with a more detailed explaination.

@kaicataldo There are a few blog posts like this one out there you should be able to use a an alternative to the link nifanic provided. I can’t speak about their correctness though, since I didn’t publish any packages to the Github registry yet.