25

I have a Lerna monorepo on Github Enterprise which currently has two npm packages that I'm trying to publish to the Github package registry under the same repo.

For reference say they are:

  • github.com/mycompany/package-a
  • github.com/mycompany/package-b

I followed these instructions: https://help.github.com/en/github/managing-packages-with-github-packages/configuring-npm-for-use-with-github-packages#publishing-multiple-packages-to-the-same-repository

So now my 2 package.json files look like the following (trimmed for formatting purposes):

"name": "@mycompany/package-a",
"repository": {
    "url": "ssh://[email protected]:mycompany/monorepo.git"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },
"name": "@mycompany/package-b",
"repository": {
    "url": "ssh://[email protected]:mycompany/monorepo.git"
  },
  "publishConfig": {
    "registry": "https://npm.pkg.github.com/"
  },

So you can notice they both have the same URL for the repository as recommended.

First problem: One is that my company already has repos called package-a and package-b. It seems that you can't have a naming collision with a package in a monorepo and a package outside the monorepo.¹

Second and more important problem: This doesn't seem to work for me at all. I renamed the package in their respective package.json files to avoid the naming collision to package-a-mono and package-b-mono which I don't really want to do but I'm just trying to get it to work. I get a 404 when trying to run either lerna publish or npm publish inside of the repos themselves. Like it's not actually trying to read that repository.url field in that it tells you to modify.

^ This turned out to be temporary or was never actually an issue, it was just because of the naming conflicts.

npm publish output:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/@mycompany%2fpackage-a - The expected resource was not found.

lerna publish output:

lerna http fetch PUT 404 https://npm.pkg.github.com/mycompany/@mycompany%2fpackage-a 327ms
lerna ERR! E404 The expected resource was not found.

Has anyone run into this and found a solution?

¹On a somewhat worse note, for some reason the very first time I ran this it actually did publish a package into the monorepo for package-a. But from then on I get the error lerna ERR! E422 Package "package-a" is already associated with another repository. Nothing changed and I couldn't publish another version to the same repo.

1
  • Have you made any progress on this?
    – Tyson Nero
    Commented Jan 9, 2020 at 20:58

4 Answers 4

11

Another possible cause of this error (discussed and ruled out in the original question body) is if any package's package.json's repository field does not match the git URL of the repo - for example, if you transferred the repo to a different organisation, or renamed the repo, but didn't update every package's package.json with the new URL.

The error message will report 404 on https://npm.pkg.github.com/@org/package-name even if the problem is with the repository URL.

(credit to jonas-reif's comment)

4
  • 1
    You saved me a couple of hours! Thanks!
    – Dominik
    Commented Jul 27, 2020 at 12:58
  • 1
    Thank you! After renaming the repo, I didn't realize I have to update the repository URL field. This is not obvious anywhere!
    – TetraDev
    Commented May 4, 2021 at 18:44
  • Many thanks for this. I might not have thought to look at the registry otherwise and found the typo.
    – Jack
    Commented Jan 22, 2022 at 22:10
  • I know I'm very late to this, but if someone stumbles upon the same problem: Another possible cause of this error ...) is if any package's package.json's repository field does not match the git URL of the repo This can be fixed by simply filling the "repository" field in package.json correctly.
    – jiri-vyc
    Commented Apr 22, 2022 at 12:16
6

The issue here was that we had repos in the organization with the same name as the package being published and it didn't like that.

When I looped back around to solving this I renamed the packages to not have a collision with another existing repo in the organization and it worked as expected.

3
  • This is pretty awkward. We have a package called "utilities" that holds utilities in various languages, one of which is node. Now we have to rename the node package so it's not just "@organization/utilities".
    – River Tam
    Commented May 21, 2020 at 15:18
  • Is there any documentation on that rule? I've been running into the same issue.
    – GN.
    Commented Oct 14, 2020 at 8:17
  • 2
    @GN. I couldn't find any documentation on it originally (and I haven't been back through the documentation since), ended up solving just based on my observations and trial and error.
    – MVarrieur
    Commented Oct 14, 2020 at 12:18
5

I ran into the same issue, I had to generate a new personal access token that had more privileges. Just read:packages and write:packages was not sufficient, you also needed repo.

5
  • what permissions did you add?
    – Peter
    Commented Mar 8, 2020 at 10:02
  • 2
    I can't confirme that. Tried to add an access token with all permissions with no luck...
    – Jonas Reif
    Commented Mar 20, 2020 at 19:18
  • 3
    For me I forgot to update my repository url in my package.json after renaming my repository...
    – Jonas Reif
    Commented Mar 20, 2020 at 19:24
  • 2
    With private repositories I've had problems with access tokens that only had package read / create privileges and needed to add repository privileges too, but I don't think it was related to this specific error. Commented Jun 12, 2020 at 17:01
  • +1 you do in fact get this very same 404 "resource not found" with the github npm URL shown in the error message when you don't have repo privileges.. very misleading error message.
    – C S
    Commented Sep 8, 2020 at 19:02
0

I had the same problem and I had to add the following line to my NPM package's URL:

"repository": "https://github.com/ACCOUNT/REPOSITORY"

This repository was the root of my mono repository.

More on this here: https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-npm-registry#publishing-multiple-packages-to-the-same-repository

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.