31

我正在尝试在我们的环境中设置 Yarn 0.17.9,但我的注册表有问题。我们目前正在使用两个注册中心,官方的 npmjs 和我们自己的内部网络注册中心(Sinopia)。

问题是我们正在使用内部工具通过 --registry 标志从一个或另一个中提取包npm installyarn add没有 --registry 选项,我无法全局设置自定义注册表并回退到 npmjs。我试过.npmrc了,但它只为项目中的 npm/yarn 设置了一个注册表。.yarnrc似乎不起作用,并且被.npmrc

有没有办法指定两个注册表(如果在第一个注册表中找不到包,则回退到第二个注册表)?或者为每个包指定不同的 npm 注册表?

4

4 回答 4

9

您可以.yarnrc在项目的根目录中创建一个文件,然后在该文件中写入这一行:

registry "https://registry.npmjs.org/"

这将充当特定于项目的存储库。

于 2017-09-01T12:51:38.720 回答
8

Yarn 不支持 --registry 标志作为 npm,但您可以在 .yarnrc 中设置注册表

如果您的 .yarnrc 被忽略,可以使用以下命令将其从 ~/.yarnrc 中复制出来:

yarn config set registry http://registry.com/registry//
于 2016-11-28T14:43:00.927 回答
5

您可以尝试在.npmrc和中设置不同的注册表.yarnrc

例如:在.npmrc

registry=https://yourcompany/
virtual/:_authToken=credentials
always-auth=true

always-auth=true必须是文件的最后一行

并在.yarnrc

registry "https://registry.yarnpkg.com"

然后yarn add/ npm install+ private-pakage/public-packge 将起作用。

于 2019-08-03T08:30:13.903 回答
3

对于在 2021 年发现这一点的任何人,yarn 现在可以与scopes、 private registries 和 auth一起使用。

例如,我已经发布了私有包,例如VerdaccioSinopia@my-company-private-scope/my-package的分支)服务器,我的配置如下:.npmrc

; Lines starting with ; are for .npmrc file comments
; yarn 1.22.10 seems to default registry to https://registry.yarnpkg.com
; no matter what I put here /shrug
; registry=https://registry.npmjs.com/

@my-company-private-scope:registry=https://npm.my-company.com/
//npm.my-company.com/:_authToken=TOKEN

; I did not seem to need this, as
; yarn still installed public and private packages successfully
; based on what ended up in my yarn.lock file
; //npm.my-company.com/:always-auth true

看起来npm 也支持 scopes,虽然yarn unpublish不存在,但npm unpublish @my-company-private-scope/my-package@1.0.1-5效果也很好。

我还不需要在多个私有服务器上尝试多个范围(尽管可能),但是我也没有看到任何好的理由它也不能很好地工作。

于 2021-08-26T03:22:35.700 回答