Publishing Github packages for a monorepo as part of an organization
Asked Answered
E

4

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.

Edd answered 6/1, 2020 at 20:45 Comment(1)
Have you made any progress on this?Specular
E
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.

Edd answered 7/4, 2020 at 17:37 Comment(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".Jeter
Is there any documentation on that rule? I've been running into the same issue.Hyalite
@Hyalite 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.Edd
K
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)

Kwakiutl answered 12/6, 2020 at 14:47 Comment(4)
You saved me a couple of hours! Thanks!Quadrifid
Thank you! After renaming the repo, I didn't realize I have to update the repository URL field. This is not obvious anywhere!Stoffel
Many thanks for this. I might not have thought to look at the registry otherwise and found the typo.Pus
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.Kneel
E
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.

Edd answered 7/4, 2020 at 17:37 Comment(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".Jeter
Is there any documentation on that rule? I've been running into the same issue.Hyalite
@Hyalite 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.Edd
D
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.

Deathful answered 27/1, 2020 at 15:39 Comment(5)
what permissions did you add?Pocosin
I can't confirme that. Tried to add an access token with all permissions with no luck...Pneumograph
For me I forgot to update my repository url in my package.json after renaming my repository...Pneumograph
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.Kwakiutl
+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.Temperance
H
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

Hasty answered 2/7, 2022 at 12:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.