github - Yarn 找不到私有(private) Github npm 注册表

标签 github npm yarnpkg

我注册了 Github 私有(private) npm 注册表测试版并按照他们的指示操作:https://github.com/features/package-registry

与 npm 配合得很好,但我更喜欢使用 yarn 。虽然 npm 找到注册的包没有问题,但yarn 根本找不到它。

yarn add @omniphx/adminite-adminite-ui-components 输出:

yarn add v1.19.0
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
error Couldn't find package "@omniphx/adminite-ui-components" on the "npm" registry.
info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

在阅读了有关yarn的私有(private)存储库后,我认为这个技巧是由于yarn的rc格式略有不同。不幸的是,这也不起作用,yarn 仍然无法找到私有(private)注册表。

.npmrc

registry=https://registry.npmjs.org
@omniphx:registry=https://npm.pkg.github.com/omniphx

.yarnrc

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

还确认我的 github token 也通过 yarn 配置列表 设置:

yarn config v1.19.0
info yarn config
{
  'version-tag-prefix': 'v',
  'version-git-tag': true,
  'version-commit-hooks': true,
  'version-git-sign': false,
  'version-git-message': 'v%s',
  'init-version': '1.0.0',
  'init-license': 'MIT',
  'save-prefix': '^',
  'bin-links': true,
  'ignore-scripts': false,
  'ignore-optional': false,
  registry: 'https://registry.npmjs.org',
  'strict-ssl': true,
  'user-agent': 'yarn/1.19.0 npm/? node/v12.11.1 darwin x64',
  email: 'mattjmitchener@gmail.com',
  lastUpdateCheck: 1570679687836,
  username: 'omniphx',
  '@omniphx:registry': 'https://npm.pkg.github.com/omniphx'
}
info npm config
{
  '//npm.pkg.github.com/:_authToken': 'fake12345',
  registry: 'https://registry.npmjs.org',
  '@omniphx:registry': 'https://npm.pkg.github.com/omniphx',
  python: '/usr/bin/python'
}

有什么想法吗?

<小时/>

已解决

Changed "@myorg:registry" "https://npm.pkg.github.com/myorg"
To      "@myorg:registry" "https://npm.pkg.github.com"

最佳答案

我刚刚也遇到过类似的情况。似乎 yarn 只在主 Yarn 包注册表中查找我组织的私有(private)包。我已将 GitHub 的 Packages 文档中用于构建 .npmrc 文件的示例直接复制到将使用该应用程序的项目中的 .yarnrc 文件,但不知道这些格式是不同的(我以前从未处理过 .yarnrc 文件)。

但是,在使用上面提到的正确格式(我也在谷歌搜索中找到)更新 .yarnrc 文件后,yarn 成功找到了私有(private)打包并正确安装。

请注意,我的 yarn 版本:1.17.3

我采取的步骤

  1. 启动新的终端 session
  2. cd 到项目
  3. nvm use(如果您有要使用的特定节点版本)
  4. 将格式正确的 .yarnrc 文件添加到项目中。请参阅下面的内容了解它的外观。
  5. 手动将软件包和版本范围添加到我的私有(private)软件包的package.json
  6. 运行npm login --registry=https://npm.pkg.github.com --scope=@MyOrg
    • 请参阅下面有关范围/组织问题的注释
  7. 运行 yarn

这对我有用。

.yarnrc

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

注意:请参阅下面有关组织/范围名称陷阱的说明

其他说明

我知道,鉴于您上面的 GH 用户名/范围,您似乎对此没有任何问题,但对于来到这里的其他人来说,GH 上的文档在映射您的用户名/方面有点稀疏org 名称到包名称中的范围。请记住这些小问题就在这里:

  • 您的软件包名称必须始终以您的组织(或用户名)为范围
    • 例如,名称:@johndturn/my-package
  • 如果您的组织中包含大写字母,例如 MyOrg,只需将它们替换为 package.json 中的包名称即可 你的 .yarnrc 小写
    • 例如,名称:@myorg/my-package
    • 注意:使用 npm login 进行身份验证时,我仍然在 --scope= 参数中保留大写字母。
  • 包的名称不必与存储库的名称相同。
    • 例如,对于名为 MyOrg/random-prefix.js-lib 的存储库,您的包中可以包含 name: @myorg/js-lib项目本身的 .json 文件。然后,将其安装在其他项目中将类似于 @myorg/js-lib: 1.0.0

关于github - Yarn 找不到私有(private) Github npm 注册表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58316109/

相关文章:

docker - 如何在 CircleCI 中为 Docker 镜像构建缓存 Yarn 依赖项?

github - git push -u origin master 失败

sql - Node.js - sqlstring 替代方案,允许命名替换

windows - 带有 yarn 的终端中的不可见文本

node.js - Node sqlite node-gyp 构建错误 : no member named 'ForceSet' in 'v8::Object'

javascript - 为本地开发创建不同的 eslint 规则

github - 让 github 语法高亮我的文件

git - 在提交到 master 后如何撤销所做的更改?

javascript - 可以通过浏览器上传文件到github页面吗?

typescript - 如何在 typescript monorepo 中导入本地包