Petros Kyriakoupersonal blog

I am a full stack web developer. Love tinkering all the time, especially anything javascript related.

How to add a private registry to yarn 2

February 16, 2020

cover image

How to add a private registry to yarn 2

Yarn 2 came out a few weeks back as the new hot kid in town. It has a lot of new features but it also lacks a bit of documentation. In this short tutorial we are going to learn how to add a private registry in easy steps.

Setup

The first you need to is obviously setup yarn 2. If you haven't done that already look here.

Adding a private registry

After you setup yarn 2, a .yarnrc.yml file should have been created.

---
npmRegistryServer: 'http://your-artifactory-link-here.com'

I purposefully left the s in http(s) out to note that if you add a non-secure url to a registry yarn 2 won't blindly accept it. Which leads to the part that the documentation is missing but can be found using the command yarn config.

---
npmRegistryServer: 'http://your-artifactory-link-here.com'
unsafeHttpWhitelist: ['your-artifactory-link-here.com'] # add domain only without protocol

As we can observe above, you need to add manually the registry to a whitelist if you want to use a non-secure connection. We don't cover things like authentication but for further options you can take a look here

Conclusion

Well this is really short but I hope you found value in it. What do you think of Yarn 2 and its new plug-n-play attitude?