简体   繁体   中英

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

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": "git@github.myorganization/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/common@0.0.7' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM