从Github软件包注册表安装私有软件包失败,未找到/未授权 [英] Installing private package from Github Package registry fails with not found/not authorized

查看:196
本文介绍了从Github软件包注册表安装私有软件包失败,未找到/未授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建并发布了一个私有的Github软件包.首先尝试用纱线安装它,我遇到以下问题:

I created and published a private Github package. Trying to install it with yarn at first, I face the following issue:

尽管我尝试使用yarn或npm,它完全找不到软件包,尽管遵循Github(

Whether I try with yarn or npm, it cannot find the package at all although following the exact steps documented by Github (https://help.github.com/en/github/managing-packages-with-github-package-registry/configuring-npm-for-use-with-github-package-registry).

我的.yarnrc:

registry "https://npm.pkg.github.com/OWNER"

对于纱线,它会不断尝试在https://registry.yarnpkg.com/@GITHUB_USERNAME处寻找包裹,而不是我在上面输入的注册表.

With yarn, it continuously tries to look for the package at https://registry.yarnpkg.com/@GITHUB_USERNAME instead of the registry I entered above.

备注:.yarnrc中的注册表需要以略有不同的语法添加:

Remark: in .yarnrc registries need to be added following a slightly different syntax:

registry "https://npm.pkg.github.com/"

到目前为止,我也开始尝试混合使用.npmrc.yarnrc配置,但是没有运气.

So far I started to also play around with a mix of .npmrc and .yarnrc configurations but no luck.

-

编辑(已部分解决)

我想出了如何实际使用npm或(在我的情况下)yarn来访问软件包的方法.现在,我遇到了Request failed \"401 Unauthorized\"错误的问题,尽管我在.yarnrc顶部添加了凭据:

I figured out how to actually access the package, both using npm or - in my case - yarn. Now I face the issue of a Request failed \"401 Unauthorized\" error, although I added the credentials on top of .yarnrc:

//npm.pkg.github.com/:_authToken=AUTH_TOKEN

.npmrc中执行相同操作也不起作用.

Doing the same in .npmrc doesn't work either.

推荐答案

不幸的是,我发现该解决方案在任何地方都没有得到很好的记录,而是混合了多种不同的资源-而且非常简单.

I found the solution which unfortunately is not well documented anywhere but a mix of different resources - and it's quite simple.

无论您使用的是npm还是yarn,都只需放置以下.npmrc(纱线也将包含此内容):

No matter whether you use npm or yarn, just have the following .npmrc in place (yarn will also include this):

registry=https://registry.yarnpkg.com/

@GITHUB_USERNAME:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=AUTH_TOKEN
always-auth=true

一些评论:

  • always-auth是必需的,至少在使用纱线时(尚未使用npm进行测试)
  • .yarnrc中添加上述内容无效.需要身份验证时,毛线会以某种方式出现问题.
  • 现在,您可以使用yarn add @GITHUB_USERNAME/PACKAGE_NAME或等效的npm轻松安装私有软件包.
  • 为纱线添加registry=https://registry.yarnpkg.com/或为npm添加registry=https://registry.npmjs.org/
  • always-auth is needed, at least when using yarn (haven't tested using npm)
  • Adding the above in the .yarnrc instead doesn't work. Somehow yarn has issues when authentication is needed.
  • Now you can easily install your private packages with yarn add @GITHUB_USERNAME/PACKAGE_NAME or the npm equivalent.
  • Include registry=https://registry.yarnpkg.com/ for yarn or registry=https://registry.npmjs.org/ for npm

我希望这种解决方案也适用于您的情况.否则,请让我知道您面临的问题,并且很高兴与您分享有关此主题的一些研究以及解决方案的隐患.

I hope this solution works also in your case. Otherwise let me know what issues you face and I'm happy to share some of the research on this topic and where the solution may hide.

这篇关于从Github软件包注册表安装私有软件包失败,未找到/未授权的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆