纱线找不到私有的Github NPM注册表 [英] Yarn can't find private Github npm registry

查看:18
本文介绍了纱线找不到私有的Github NPM注册表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注册了Github私有NPM注册测试版,并遵循了他们的说明:https://github.com/features/package-registry

与NPM配合使用效果很好,但我更喜欢使用纱线。虽然NPM可以毫不费力地找到注册的包裹,但纱线根本找不到它。

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.

在阅读了有关纱线的私人回复后,我认为这个技巧是由于纱线的RC格式略有不同。不幸的是,这也不起作用,纱线仍然无法找到私有注册表。

.npmrc

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

.ya nrc

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

还确认我的GitHub令牌也设置了yarn config list

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包注册表中查找我组织的私有包。我已经将构建.npmrc文件的GitHub包文档中的示例直接复制到将使用该应用程序的项目中的.yarnrc文件,而不知道格式不同(我以前从未处理过.yarnrc文件)。

但是,在使用您上面提到的正确格式更新.yarnrc文件之后(我在搜索中也发现了这一点),yarn成功地找到了私有包并正确安装了它。

提醒一下,我的yarn版本:1.17.3

我采取的步骤

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

这对我很管用。

.ya nrc

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

注意:有关组织/作用域名称的注意事项,请参阅下面的说明

其他备注

我知道您在上面的GH用户名/作用域中似乎没有任何问题,但是对于其他任何人来说,关于GH的文档在将您的用户名/组织名映射到包名中的作用域方面略显稀疏。只需记住以下小问题:

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

这篇关于纱线找不到私有的Github NPM注册表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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