Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Publishing Github packages for a monorepo as part of an organization

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.

like image 215
MVarrieur Avatar asked Jan 06 '20 20:01

MVarrieur


1 Answers

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)

like image 71
user56reinstatemonica8 Avatar answered Oct 16 '22 04:10

user56reinstatemonica8