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?
Yarn can consume the same package. json format as npm, and can install any package from the npm registry. This will lay out your node_modules folder using Yarn's resolution algorithm that is compatible with the node.
Yarnrc files (named this way because they must be called . yarnrc. yml ) are the one place where you'll be able to configure Yarn's internal settings. While Yarn will automatically find them in the parent directories, they should usually be kept at the root of your project (often your repository).
As previously stated, Yarn installs dependency packages in parallel, whereas NPM installs them sequentially. As a result, Yarn outperforms NPM when installing bigger files. Both tools can save dependent files to the offline cache.
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.
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//
For anyone finding this in 2021, yarn now can work with scopes, private registries and auth.
For example, I have published private packages such as @my-company-private-scope/my-package
to a Verdaccio (fork of Sinopia) server and my .npmrc
configuration is like:
; 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
It looks like npm also supports scopes, in that while yarn unpublish
doesn't exist, npm unpublish @my-company-private-scope/[email protected]
also worked beautifully.
I don't have a need to try multiple scopes on multiple private servers yet (though might), however I also don't see any good reason it wouldn't work beautifully too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With