简体   繁体   English

作为一个组织,你如何发布和安装私有的 npm package 到 GitHub 包?

[英]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.我们有一个名为“@myorganization/common”的共享 package 的 monorepo,应用程序和 Google 云功能都使用它。

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.谷歌云功能要求将 package 发布到 repo 才能使用它,因为我们不发布编译代码,可以包含本地包,而是直接发布原始 TypeScript。

I found serveral tutorials but not for the use case of combining private packages and organizations.我找到了一些教程,但不是针对组合私有包和组织的用例。

I cd into the packages/common directory.我进入 packages/common 目录。

I added the following lines to my packages.json:我在 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.我在 GitHub 上创建了一个个人身份验证令牌,具有完整的回购、包和组织权限。

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.我希望这个 package 仅供组织成员使用。 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.它应在 lerna monorepo 中用作本地私有 package,当由 React Native 使用时,并由 Google Cloud Function 通过从 GitHub 包中获取它来使用。 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:我尝试更新 packages.json,删除 private=true 并尝试确保将其发布到我的私人组织:

"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.我必须在myorganization上创建组织(即您的示例中的 myorganization),并创建一个与该组织下的 repo 名称相同的 repo(即您的示例中的common )并且它有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 BigQuery 中安装 npm 包? - How to install npm packages in BigQuery? NPM 无法安装软件包,引用缺少 package.json - NPM cannot install packages, cites missing package.json 在 Firebase Cloud Functions 中安装 private GitHub npm package - Installing private GitHub npm package in Firebase Cloud Functions 在 Firestore 中,如何防止“请确保您使用的 Firestore 类型来自同一个 NPM 包”错误 - In Firestore, how can I prevent "Please ensure that the Firestore types you are using are from the same NPM package" errors 你如何在亚马逊 Linux 2 上安装 chrome? - How do you install chrome on Amazon Linux 2? 从 npm 私人仓库在 gitlabci 中安装 npm package - installing a npm package in gitlabci from npm private repo 通过 GitHub 操作将 Python Package 发布到 AWS CodeArtifact - Publish Python Package via GitHub Actions to AWS CodeArtifact 如何使用 Poetry 将 Python 包发布到 CodeArtifact? - How can I publish Python packages to CodeArtifact using Poetry? GCP Cloud Build 突然无法从 Github Package 获取 npm package - GCP Cloud Build suddenly cannot fetch npm package from Github Package NAT 网关-您 go 如何通过 SSH 进入私有 EC2? - NAT Gateways-how do you go about SSH'ing into the private EC2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM