How do I use multiple npm registries in Yarn?

纵然是瞬间 提交于 2019-12-03 07:18:45

问题


I'm trying to setup Yarn 0.17.9 in our environment but I have a problem with our registry. We are currently using two registries, official npmjs and our own registry on internal network (Sinopia).

The problem is that we are using internal tool to pull packages from one or the other with --registry flag via npm install. yarn add doesn't have --registry option and I'm unable to set the custom registry globally with fallback to npmjs. I tried .npmrc but it sets only one registry for npm/yarn in project. .yarnrc doesn't seem to work and is silenced by .npmrc

Is there any way to specify two registries (fallback to second registry if the package is not found in the first one)? Or specify different npm registry per package?


回答1:


Yarn doesn't have support --registry flag as npm but you can set up your registry in .yarnrc

If your .yarnrc is being ignored it can be copied out of the ~/.yarnrc using:

yarn config set registry http://registry.com/registry//



回答2:


You can make a .yarnrc file in the root of the project and write this line in that file:

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

This will act as a project specific repository.




回答3:


You can try set different registry in .npmrc and .yarnrc.

So for example: In .npmrc:

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

always-auth=true needs to be the very last line in the file

And in .yarnrc:

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

Then yarn add/npm install + private-pakage/public-packge will work.



来源:https://stackoverflow.com/questions/40845598/how-do-i-use-multiple-npm-registries-in-yarn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!