使用 Yarn 从 Github 包注册表安装私有包失败且未授权

2024-03-24

这个问题与这些有关。但这些解决方案都不适合我。

  • Yarn 找不到私有 Github npm 注册表 https://stackoverflow.com/questions/58316109/yarn-cant-find-private-github-npm-registry
  • 从 Github 包注册表安装私有包失败,并显示未找到/未授权 https://stackoverflow.com/questions/58522363/installing-private-package-from-github-package-registry-fails-with-not-found-not

我可以毫无问题地安装软件包npm install @scope/package但是我不能用纱线做同样的事情:yarn add @scope/package

纱线抛出以下错误:An unexpected error occurred: "https://npm.pkg.github.com/download/@scope/package/1.2.8/089b08cffb16074c210ec3a59b04de268ae1c7b3a0492dce110adee3ada05bdd: Request failed \"401 Unauthorized\"".

我的 .npmrc 文件如下所示:(尝试使用和不使用下面的 .yarnrc)

registry=https://registry.npmjs.org/
//npm.pkg.github.com/:_authToken=MY_AUTHTOKEN
@scope:registry=https://npm.pkg.github.com/

我尝试添加这个 .yarnrc 文件:

registry "https://registry.npmjs.org"
"@scope:registry" "https://npm.pkg.github.com"

(没有 .yarnrc)我尝试过这个 .npmrc 文件

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

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

Where MY_AUTHTOKEN is my Personal Access Token我是从 Github 生成的。 (它可以访问包中的所有内容)

我尝试过:

  • 删除纱线锁
  • 删除.yarnrc
  • 登录npm login使用我的 PAT 作为密码
  • 注销 npm 并删除全局 .npmrc 和 .yarnrc
  • 登录方式yarn login

如有任何困惑 我实际上并没有尝试 @scope 和 /package 而是我的实际范围和包名称。

我确实可以访问 Github 上的范围和包。

我的第一个设置再次与 npm 配合得很好。但我无法使用纱线来实现这一点,并且无法在 SO 上找到任何有效的现有解决方案。


以下内容对我有用.npmrc

@mvce-superstars:registry=https://npm.pkg.github.com

Using yarn v2 https://yarnpkg.com/getting-started/install,以下内容对我有用.yarnrc.yml https://yarnpkg.com/configuration/yarnrc:

npmScopes:
  "mvce-superstars":
    npmAlwaysAuth: true
    npmAuthToken: xxx-xxx # optional
    npmRegistryServer: "https://npm.pkg.github.com"

Note

范围名称是小写。这应该是名字 存储库的所有者(例如MVCE-Superstars https://github.com/MVCE-Superstars) 包裹在哪里 已发布,但名称必须全部小写。


设置

出版

  • 我创建了一个私人副本 https://help.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository这个的你好世界 https://github.com/rms1000watt/hello-world-npm.git存储库。
  • 我复制了上面的内容.npmrc OR .yarnrc.yml文件到存储库中。
  • 接下来我使用以下方式登录npm login --registry=https://npm.pkg.github.com/ OR yarn npm login --scope=mvce-superstars命令 (skip if npmAuthToken https://yarnpkg.com/configuration/yarnrc#npmAuthToken上面指定了)
  • 我输入了我的 github 用户名,以及我的token https://github.com/settings/tokens(带范围read:package, write:package, and repo) (skip if npmAuthToken上面指定了)
  • 最后,我使用将包推送到我的私人仓库npm publish OR yarn npm publish

Output

npm notice 
npm notice ????  @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
npm notice === Tarball Contents === 
npm notice 16.3kB example.gif   
npm notice 89B    bin.js        
npm notice 175B   lib/index.js  
npm notice 734B   package.json  
npm notice 2.0kB  yarn-error.log
npm notice 570B   Readme.md     
npm notice 167B   init.sh       
npm notice === Tarball Details === 
npm notice name:          @mvce-superstars/hello-world-npm        
npm notice version:       1.1.1                                   
npm notice package size:  14.3 kB                                 
npm notice unpacked size: 20.0 kB                                 
npm notice shasum:        5379c8030fa9c5f57e5baef67f2a8a784ce93361
npm notice integrity:     sha512-FAI/Wuy4gHW8C[...]FINQeIlZ+HDdg==
npm notice total files:   7                                       
npm notice 
+ @mvce-superstars/[email protected] /cdn-cgi/l/email-protection

正在下载

  • 我使用创建一个新的 npm 项目npm init (use-hello-world-npm)
  • 我复制上面的.npmrc到文件夹的根目录
  • 接下来我注销 npm (npm logout --registry=https://npm.pkg.github.com/) 并重新登录 (npm login --registry=https://npm.pkg.github.com/), 只是要确定
  • 最后,我跑yarn就像它应该的那样,它起作用了!

Output

yarn install v1.22.4
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.55s.

yarn v2

➤ YN0000: ┌ Resolution step
➤ YN0014: │ @mvce-superstars/hello-world-npm@npm:^1.1.1: Only some patterns can be imported from legacy lockfiles (not "https://npm.pkg.github.com/download/@mvce-superstars/hello-world-npm/1.1.1/426126f89734c2c76bfac0342c1de9c95ad003b6e905a7b9f9f745892c86da7a#5379c8030fa9c5f57e5baef67f2a8a784ce93361")
➤ YN0000: └ Completed in 0.55s
➤ YN0000: ┌ Fetch step
➤ YN0013: │ @mvce-superstars/hello-world-npm@npm:1.1.1::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40mvce-superstars%2Fhello-world-npm%2F1.1.1%2F426126f89734c2c76bfac0342c1de9c95ad003b6e905a7b9f9f745892c86da7a can't be found in the cache and will be fetched from the remote server
➤ YN0000: └ Completed in 1.3s
➤ YN0000: ┌ Link step
➤ YN0031: │ One or more node_modules have been detected and will be removed. This operation may take some time.
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 1.87s

之后的文件夹内容yarn

.
├── node_modules
│   └── @mvce-superstars
├── package.json
└── yarn.lock

为了更好地衡量,我将其删除(yarn remove @mvce-superstars/hello-world-npm):

yarn remove v1.22.4
[1/2] Removing module @mvce-superstars/hello-world-npm...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
Done in 0.06s.

并再次添加(yarn add @mvce-superstars/hello-world-npm):

yarn add v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
info All dependencies
└─ @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
Done in 1.08s.

Sources:

  • https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages
  • https://gemfury.com/help/private-yarn/ https://gemfury.com/help/private-yarn/
  • https://github.com/yarnpkg/yarn/issues/4451 https://github.com/yarnpkg/yarn/issues/4451
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用 Yarn 从 Github 包注册表安装私有包失败且未授权 的相关文章

随机推荐

  • 在 eclipse RCP 中安装新插件/功能后,是否有任何方法可以自动从磁盘中清除旧插件/功能?

    我正在构建一个 RCP 应用程序 每个季度都会更新功能 插件 因此 如果用户选择自动更新功能 插件 则将下载更新插件的新 jar 但旧插件仍在使用我不再使用的磁盘空间 我厌倦了删除包含旧 jar 信息的安装历史记录 当我尝试删除它时 它向我
  • 我们什么时候应该使用 RxJS tap 运算符?

    我不明白从the docs https rxjs dev firebaseapp com api operators tap 有人能给我解释一下吗 大多数操作符都按流顺序工作 例如 source pipe map a string gt c
  • 如何将支持的操作系统添加到 Windows 单击一次应用程序清单中?

    我正在尝试将supportedOS标签添加到单击一次应用程序清单中 对于常规应用程序执行此操作的常用方法是将 app manifest 文件添加到包含supportedOS 标记的项目中 如下所示 我删除了自动生成的单击一次清单中已包含的所
  • 在 Swift 中将两字节 UInt8 数组转换为 UInt16

    使用 Swift 我想将 uint8 t 数组中的字节转换为整数 C 示例 char bytes 2 0x01 0x02 NSData data NSData dataWithBytes bytes length 2 NSLog data
  • Vue.js 从 webpack 包中排除文件夹

    我陷入了一个关于 webpack 的非常简单的问题 我有一个使用 vue cli 创建的简单 Vue js 应用程序 我创建了文件夹public Reports我想从捆绑包中排除它 该文件夹包含子文件夹和 PDF 我的项目结构是标准的 di
  • 从边框外部绝对定位

    当我将元素绝对定位在相对元素内时 坐标是从容器的边缘计算的 而不考虑边框 相当于从边框的内侧定位 除了从边框的外侧定位元素之外 还有什么方法可以定位元素吗 例如 如果我有一个没有边框的红色方块 如第一个 则文本会粘在容器的左上角 因为它有t
  • PHP PHAR 归档的优点

    PHP 5 3 有一个新功能称为PHAR如同JAR在JAVA中 它基本上是 PHP 文件的存档 它的优点是什么 我不明白它们在网络场景中有何帮助 除 易于部署 之外的任何其他用途 只需复制一个文件即可部署整个应用程序 开源项目有巨大的好处
  • 从 JavaScript 字符串中去除 U+10000-U+10FFFF

    Tried string replace u10000 u10FFFF g 但可悲的是 u不支持10000 要指定超出 U FFFF 的代码点 您需要查找UTF 16 代理对 https en wikipedia org wiki UTF
  • 放大黑线的阈值

    给定一张图像 如下图所示 我需要将其转换为二进制图像 仅限黑白像素 这听起来很简单 我尝试过两个阈值函数 问题是我无法使用这些函数中的任何一个来获得完美的边缘 任何帮助将不胜感激 我尝试过的过滤器是 RGB 和 HSV 空间中的欧几里得距离
  • 在 C++ 中写入相同值的竞争条件?

    当操作写入单个常量值时 代码中存在竞争条件是否存在任何问题 例如 如果有一个并行循环填充了seen另一个数组中的每个值的数组arr 假设索引越界没有问题 关键部分可能是以下代码 parallel body with index i int
  • mongodb查询嵌套结构

    如何查询此嵌套 json 结构以查找包含 A 的文档 categories id 12 values A B C id 17 values D E F 到目前为止 我只能通过以下方式获取 id 值 db coll find categori
  • 有没有办法专注于 Angular 4/Ionic 3 上动态创建的表单?

    I have a page with dynamically created forms like this The blank spaces are inputs and the entire row is a button Is the
  • 如何在H2中创建新数据库?

    我有一个在 MySQL 上本地运行的站点 我想在 H2 数据库上运行它 我刚刚在浏览器上运行了控制台的 h2 jar 文件 但每当我登录时我都会看到该列表jdbc h2 var www mysite data db MODE MySQL i
  • Kubernetes 上的 Npgsql 和 Pgbouncer - 池化和 keepalives

    我正在寻找更详细的指导 其他人在 Pgbouncer 的生产中使用 Npgsql 的经验 基本上 我们使用 GKE 和 Google Cloud SQL 进行了以下设置 现在 我已经使用本地连接池配置了 npgsql 就好像 pgbounc
  • 如何使用 CSS 并排浮动 3 个 div?

    我知道如何让 2 个 div 并排浮动 只需将一个向左浮动 另一个向右浮动即可 但是如何使用 3 个 div 来做到这一点 或者我应该仅使用表格来实现此目的 只需给它们一个宽度并float left 这是一个例子 div style wid
  • 有没有办法限制ggplot2中的vline长度

    我试图使用 ggplot vline 和 hline 在线图上显示截距 但希望线条在图上的截距点处停止 在 ggplot 中这可能吗还是有其他解决方案 library ggplot2 pshare lt data frame for i i
  • 如何在 C# 中将复杂对象作为结构进行比较以进行单元测试

    我遇到了以下问题 目前我正在使用 TDD 重构我的项目 有一个已存在的域 我无法更改 代码示例 public class Product IEquatable
  • 使用带有 AutoGenerateColumns="True" 的 DataGrid 时,为什么会忽略 DataAnnotations

    我正在使用 WPF DataGrid 绑定到自定义类的集合 在网格 XAML 中使用 AutoGenerateColumns True 可以很好地创建和填充网格 但正如人们所期望的那样 标题是属性名称 我尝试指定
  • 从父类调用setup_data

    背景 我正在阅读关于如何将自我调整文本放入栏中的优秀答案 条内可调整大小的文本块 https stackoverflow com questions 36319229 ggplot2 geom text resize with the pl
  • 使用 Yarn 从 Github 包注册表安装私有包失败且未授权

    这个问题与这些有关 但这些解决方案都不适合我 Yarn 找不到私有 Github npm 注册表 https stackoverflow com questions 58316109 yarn cant find private githu