DEV Community

Cover image for Why upgrade to Yarn Berry?
Ashutosh Kumar
Ashutosh Kumar

Posted on

Why upgrade to Yarn Berry?

Yarn is a package manager that has gained popularity in the JavaScript community due to its speed, reliability, and ease of use. It was initially released by Facebook in 2016 as an alternative to npm, the default package manager for NodeJS. From that point onwards, it just kept growing.

Yarn has been a staple in the JavaScript community for years, but it just outdid itself with the release of Yarn Berry. It's like Yarn on steroids, and it's packing some serious punches. So, why upgrade to Yarn Berry, you ask? Let's dive in.

What changed?

Let me tell you a little story about how Yarn Berry came to be. It all started with one brave soul who decided to take on the pesky node_modules directory. You know, that clunky beast that can get as heavy as a black hole in your project and suck it in if you're not careful. Say goodbye to the old days of node_modules with Yarn Berry! Thanks to its global cache, you can now enjoy faster and more efficient package installations without worrying about disk space or cluttered file systems.

Trust me. It is fast.

Yarn v3 is like a superhero, swooping in to save the day with its Berrylicious superfast speed! Its new architecture and Plug'n'Play system. But why trust me, when you can look at it yourself.

I'm gonna install dotenv, express, passport into my project folder for each of the package manager, and after that I'm just gonna run yarn install in both of these, to see which runs faster.

Yarn v1 took 160ms to install

Well that was fast, only 160ms. Way to go Yarn v1.

Yarn berry was just 64ms

It was only 64ms, Less than half of v1.
So, to all the doubters out there, I say this: Trust me, I know what I'm talking about. Don't let your trust issues get in the way of experiencing the magic of Yarn Berry.

What is even this Plug'n'Play?

Think of the "Plug'n'Play" system in Yarn berry like a shared pantry in a big office building. Instead of every employee bringing in their own snacks and drinks and storing them in their individual cubicles, there's a central pantry where everyone can access the same goodies. This saves space in individual cubicles, avoids duplicate snacks, and makes it easier for everyone to find what they need without having to search through their own personal stash.

Similarly, with Yarn berry, instead of each project having its own "pantry" of packages in the node_modules directory, they all share the same "pantry" in the global cache. This saves space on your computer, avoids duplicate packages, and makes it faster to install the packages you need for your project.

Yarn plug'n'play diagram

Does it really helps in minimising dependency collision?

In Yarn v3, workspaces are an important feature that allows you to work with multiple packages as if they were a single project. This is particularly useful if you have a large codebase with many interdependent packages, or if you're working on a monorepo.

With Yarn v3, you can define a workspace in your project's package.json file, which lists all the packages you want to work with. Yarn will then link all these packages together so that you can work on them as if they were a single project.

One of the benefits of this approach is that you can share dependencies between packages. For example, if you have two packages that both depend on the same version of React, you can define React as a dependency in your root package.json file, and then both packages will use the same version of React.

No more conflicts between package versions, as Yarn v3 keeps everything in line like a drill sergeant. Plus, you'll have less duplication in your codebase, as you only need to install each package once. It's like decluttering your closet, but for your project.

Cache Me If You Can: Yarn v3's Groovy Package Caching System

Yarn v3 comes with a new and improved caching system that makes package caching more efficient and effective than ever before. The caching system is smarter and more optimised. Yarn v3's caching system is always up-to-date, so you'll never feel like you're stuck in the past with outdated packages. It's like having a personal package stylist that always keeps you on trend.

Yarn's Got It Together: Improved Stability!

Yarn v3, also known as "Berry" is the result of years of experience and hard work. With this new version, the Yarn team has finally been able to fix longstanding design issues that had been plaguing the previous version, known as "Classic."

Stable Yarn

Thanks to a streamlined resolution pipeline, improved data structures, and the inclusion of workspaces as core components, Yarn v3 is significantly less likely to suffer from incorrect assumptions and other design flaws. In short, Yarn v3 is a modern marvel that developers can rely on for stable and efficient package management.

Conclusion

In a nutshell, upgrading to Yarn v3 Berry offers a wide range of benefits, including improved performance, workspace management, and error reporting. If these reasons don't sway you, then I'm not sure what will! So, don't be hesitant, embrace the upgrade and experience the positive impact on your project's dependencies management. Let's get groovy and upgrade to Yarn v3 Berry!

And as always, Thanks for reading!!

Top comments (16)

Collapse
 
ankurk91 profile image
Ankur K

I switched to pnpm.
I no longer recommand yarn

Collapse
 
raxraj profile image
Ashutosh Kumar

Oh but yarn Berry is just beautiful to see at work. And I dunno even the yarn v1 is beautiful. I dunno pnpm is just too hyped according to me, probably cause it's newer. At the end what suits your team and your project that's what matters.

Collapse
 
eshimischi profile image
eshimischi

Well, first it is not hyped.. Vue community and a lot of projects on Github chose pnpm and workspaces as a tool, it speaks for itself

Thread Thread
 
raxraj profile image
Ashutosh Kumar

Alright buddy!
I'd say Pnpm is better. I'm a yarn user. I love to make case for it. :)

Thread Thread
 
eshimischi profile image
eshimischi

Not here to disrespect your choice, up to you as i said. Everyone is choosing what is best for them. I’m just see Github tendency the last year and what community does prefer

Thread Thread
 
chadgauth profile image
Chad Gauthier

sometimes people just choose what is familiar not best

Collapse
 
eshimischi profile image
eshimischi

No need for either yarn or npm, use pnpm instead

Collapse
 
raxraj profile image
Ashutosh Kumar

Hihihi I wish I could agree. I really do.
I was using pnpm in my few projects, and I dunno how to explain this. Yarn felt more Natural. It just did.

Collapse
 
eshimischi profile image
eshimischi

It’s up to you. Pnpm has less files in node_modules and faster, to speak about pros

Thread Thread
 
raxraj profile image
Ashutosh Kumar

It doesn't have less files. It's just it has less folders to see on the top level of node modules. I'd run test over test I'll always find that Yarn is faster.
Probably pnpm suits you more than anything.

Thread Thread
 
eshimischi profile image
eshimischi

Again it is your experience, never ever saw yarn being faster, so.

Thread Thread
 
raxraj profile image
Ashutosh Kumar

Probably just my experience.
I'd enjoy the yarn as long as I can till the day I switch to something better 😁😁😁

Thread Thread
 
eshimischi profile image
Thread Thread
 
raxraj profile image
Ashutosh Kumar

This is from the article I can see at times yarn PNP is faster, other times Yarn, other times Pnpm and even npm gets like 3 times faster compared to both the other times.

I'd like to conduct a test and benchmarks with proper investigation. Let's do it man! Let's actually settle this.

Collapse
 
devgancode profile image
Ganesh Patil

Package managers are essentials to learn and I started with npm but still not figuring out should I shift to yarn or continue with npm?

Collapse
 
raxraj profile image
Ashutosh Kumar

If you have just started and you're not into any hardcore project you can sure continue with npm, that should be fine the transition to yarn isn't a giant leap as well. So why not just see what it has to offer and choose yourselves.