纱线可以';找不到专用Github npm注册表

纱线可以';找不到专用Github npm注册表,github,npm,yarnpkg,Github,Npm,Yarnpkg,我注册了Github private npm registry beta,并按照他们的指示: 与npm配合使用效果很好,但我更喜欢使用纱线。虽然npm在查找注册包时没有问题,但yarn根本找不到 纱线添加@omniphx/adminite-adminite用户界面组件输出: yarn add v1.19.0 info No lockfile found. warning package-lock.json found. Your project contains lock files gener

我注册了Github private npm registry beta,并按照他们的指示:

与npm配合使用效果很好,但我更喜欢使用纱线。虽然npm在查找注册包时没有问题,但yarn根本找不到

纱线添加@omniphx/adminite-adminite用户界面组件
输出:

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] I'm not an expert with npm/yarn so I might be misunderstanding what is happening here, but I don't think package proxying from the npm registry works with yarn yet. Could that be related? When package proxying was released for npm I remember reading comments on Twitter from people that tried it with yarn and it didn't work.

Found the Twitter thread here: https://twitter.com/github/status/1171832034580451328

It doesn't work with Yarn. As soon as I change the registry url -> Couldn't find package.

I've just run into a similar situation. It seemed that
yarn
was only looking in the main Yarn package registry for my organization's private package. I had copied the examples from GitHub's Packages documentation for constructing your
.npmrc
file directly to the
.yarnrc
file in the project that will be consuming the app, not knowing that the formats were different (I've never had to deal with
.yarnrc
files before).

However, after updating the
.yarnrc
file with the correct format that you've mentioned above (which I also found in googling around),
yarn
successfully found the private package and installed it correctly.

As a heads up, my
yarn
version: 1.17.3

Steps I Took

  1. Start new terminal session
  2. cd
    to the project
  3. nvm use
    (if you have a specific node version to use)
  4. Add the correctly-formatted
    .yarnrc
    file to the project. See below for what it looks like.
  5. Manually add the package and version range to the
    package.json
    for my private package
  6. Run
    npm login --registry=https://npm.pkg.github.com --scope=@MyOrg
    • See the note below on scope / org gotcha's
  7. Run
    yarn
That worked for me.

.yarnrc

"@myorg:registry" "https://npm.pkg.github.com"
纱线添加v1.19.0
信息找不到锁文件。
找到警告package-lock.json。您的项目包含由Thread以外的工具生成的锁定文件。建议不要混合使用包管理器,以避免由不同步的锁文件导致的解决方案不一致。要清除此警告,请删除package-lock.json。

[1/4]我不是npm/Thread的专家,所以我可能会误解这里发生的事情,但我认为npm注册表中的包代理还不能用于Thread。这有关系吗?当为npm发布包代理时,我记得在Twitter上读到一些人的评论,他们用Thread尝试了它,但没有成功

在此处找到Twitter线程:

它不适用于纱线。一旦我更改注册表url->找不到包


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

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

作为提醒,我的
纱线
版本:1.17.3

我采取的步骤
  • 启动新的终端会话
  • cd
    到项目中
  • nvm使用
    (如果要使用特定的节点版本)
  • 将格式正确的
    .yarnrc
    文件添加到项目中。请参见下面的内容以了解其外观
  • 手动将包和版本范围添加到我的私有包的
    package.json
  • 运行
    npm登录--registry=https://npm.pkg.github.com --范围=@MyOrg
    • 请参见下面关于scope/org gotcha的注释
  • 运行
    纱线
  • 这对我很管用

    yarnrc先生 注意事项:有关组织/范围名称gotcha的注意事项,请参见下文

    其他注释 我知道,鉴于上述GH用户名/作用域,您似乎对此没有任何问题,但对于其他来到这里的人来说,GH的文档在将用户名/组织名称映射到包名称中的作用域方面有点稀疏。记住这些小把戏在这里:

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

      • 我遇到的问题略有不同

        在尝试了John建议的方法后,我仍然无法使用
        warn
        添加私有注册表包(但是使用
        npm
        非常好)

        然后我意识到两件事:

        对于GitHub包,
        npm
        可以使用以下两种方法之一

        注册表=https://npm.pkg.github.com/my-org

        @my-org:registry=https://npm.pkg.github.com

        但是
        warn
        只允许后一种语法

        Github网站上的文档只显示了可能会给用户带来问题的第一种语法

        另一件事是,如果您
        npm登录到私有注册表
        ,但在项目中使用
        .yarnrc
        文件,则Thread实际上无法将
        npm
        凭据与之混合。虽然它在不同的环境下表现不同


        但是坚持使用
        warn登录
        +
        .yarnrc
        ,或者
        npm登录
        +
        .npmrc
        (在这两种情况下,您仍然可以使用warn来管理包)

        此修复程序对您的情况有帮助吗?也为我工作,谢谢。现在,我想知道如何在我的CI中设置它,它不是在Github操作上运行,而是在jenkins上运行。@Dhwaneetbhat这是一个很好的问题,它应该相当简单,有一些假设。如果您在Jenkins中运行管道和
        Jenkins文件
        ,我的假设是您可以在预构建步骤中将上述命令(如
        npm login…
        )添加到
        Jenkins文件中。这还假设您已通过GitHub组织中某种用户的Jenkins身份验证,该用户具有从您的组织中提取包的正确权限。也就是说,我还没有为我们的Jenkins盒子实现它,但我会在实现时告诉你(如果它与我提到的有所不同)。谢谢你的回复!看来我的问题是我有
        “@myorg:registry”https://npm.pkg.github.com/myorg“
        而不是“@myorg:registry”https://npm.pkg.github