How do you publish and install a private npm package to GitHub packages as an organisation?
Asked Answered
P

1

6

We have a monorepo with a shared package called "@myorganization/common", that is used by both the app and Google cloud functions.

Google cloud functions requires that the package is published to a repo to use it, since we do not publish compiled code, that can include local packages, but directly the raw TypeScript.

I found serveral tutorials but not for the use case of combining private packages and organizations.

I cd into the packages/common directory.

I added the following lines to my packages.json:

"publishConfig": { "registry": "https://npm.pkg.github.com/" },
"repository": {
  "url": "[email protected]/common.git"
},

I created a personal Auth Token on GitHub with full repo, packages and org rights.

Then I login to my organization:

npm login --registry=https://npm.pkg.github.com --scope=@myorganization

Then I hit:

npm publish

I get the following error:

npm ERR! code EPRIVATE
npm ERR! This package has been marked as private
npm ERR! Remove the 'private' field from the package.json to publish it.

I want this package to be only usable by organization members. It shall be both used as a local private package within the lerna monorepo, when used by React Native, and used by Google Cloud Function by getting it from GitHub packages. Yet no other people shall be able to access it.

Is it something that is possible ?

Regards

Edit:

I tried to update packages.json, removing private=true and trying to ensure I publish it to my private organization:

"publishConfig": {
    "registry": "https://npm.pkg.github.com/:_authToken=xxxx --scope=@myorganization"
  },

I now get the error:

npm ERR! code E404
npm ERR! 404 Not Found - PUT https://npm.pkg.github.com/@myorganization%2fcommon - The expected resource was not found.
npm ERR! 404
npm ERR! 404  '@myorganization/[email protected]' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
Pilose answered 19/8, 2020 at 21:33 Comment(0)
U
2

I was facing the exact same issue. Here's what worked for me.

I had to create that organization (i.e. myorganization in your example) on GitHub and a repo with same name (i.e. common in your example) as repo under that organization and it worked.

Ula answered 16/10, 2020 at 11:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.