Yarn 3 Migration: a Guide to Benefits, Challenges, and Lessons Learned

Flavio Troia
Elty by DaVinci Salute
5 min readOct 18, 2023

I’ve been working in software development for almost twenty years, and as a veteran, I know how delicate it can be to change, especially on the fly, some of your tools or simply update them. Even more so if it’s a package manager. In other words, keeping the one that updates everything else up to date is important, isn’t it?

For the Davinci Care project I’m currently working on, it was decided, almost in its entirety, to migrate from Yarn 1.22 to Yarn 3.6.1, and I had the duty and the honor of completing this migration.

Everyone knows that it’s never a good thing to change such an important tool in the middle of a project. But, well, we don’t like the absence of risk and comfort zones that much. So, yes, we decided to take a risk, and in hindsight, I can say that we didn’t make a mistake. The choice paid off, big time!

But let’s start from the beginning.

Migrating to a new version of a package manager like Yarn can be a significant decision for a development team. The operation, among other things, turns out to be very delicate: in fact, the official website until a few days ago had a note that went something like this: “We do not yet recommend all projects to migrate to Yarn 3. Do it only if you have specific reasons to do so.”

Even though there were apparently no valid and clear reasons to update Yarn, especially in the middle of a project, the desire to experiment, to try out the new, that feeling a mechanic might have with the latest type of wrench on the market, took precedence.

It was expected that Yarn 3 could bring various improvements and optimizations compared to its predecessor, Yarn 2, or the still-in-use Yarn 1, and it’s worth considering the advantages of the migration.

The following are the advantages to consider when migrating to Yarn 3:

  1. Performance improvements: Package managers often release updates to improve their performance. If Yarn 3 offers improvements in terms of installation speed, dependency resolution, and overall efficiency, it could significantly benefit the development workflow.
  2. Simplified configuration: Newer versions of package managers might introduce simplified configuration settings, reducing the complexity of managing dependencies and project settings.
  3. Improved security: Up-to-date package managers come with enhanced security features and updated vulnerability checks to ensure your project’s dependencies are free from known vulnerabilities.
  4. Enhanced workspace support: If your project involves a monorepo structure or multiple packages, Yarn 3 could provide better workspace management, simplifying dependency management between different parts of the project.
  5. Ecosystem improvements: Yarn 3 might offer better support for various ecosystems, programming languages, and package types, which could be advantageous if your project involves a different technological stack.
  6. Community and support: Upgrading to a newer version of a package manager could provide access to an active and growing community, as well as improved support and documentation.
  7. Dependency tree optimization: Some newer package managers focus on reducing the size of the dependency tree and avoiding unnecessary duplications, resulting in smaller package sizes and faster builds.

However, before proceeding with migrations, it’s important to consider some important aspects:

  1. Compatibility: Ensure that Yarn 3 is compatible with your existing project configuration, including current dependencies, build scripts, and any custom settings you may have.
  2. Testing: Thoroughly test the migration in a non-production environment to identify any issues before applying it to the main project.
  3. Documentation and learning curve: Understand the changes and improvements introduced in Yarn 3 and ensure your team is ready to adapt to any new concepts or workflows.
  4. Rollback plan: Always have a plan in case the migration doesn’t go smoothly as expected. Being able to roll back to the previous package manager version is crucial to minimize downtime or disruptions.
  5. Community feedback: Seek out what other teams or developers are saying about their experiences with Yarn 3. This can provide insights into potential benefits and challenges.

The experience on a real project had a clearly positive outcome. The decision to migrate to Yarn 3 or any other package manager should be based on a careful assessment of the benefits it offers compared to the effort and potential challenges of migration. Keep in mind that migrations can introduce short-term disruptions, so it’s important to evaluate the long-term benefits for the project and the specific team.

In fact, on the Davinci Care project, upgrading Yarn was not a simple task, but in return, significant performance improvements were observed.

There were clear improvements in terms of software lightweightness and fluidity. The containers of the various microservices weigh less in megabytes, making the runtime much faster. Yarn 3 allows for more efficient resource management by dynamically allocating resources to applications based on their needs, avoiding overuse or underuse. More efficient resource management, greater flexibility and scalability, better application isolation, and advanced monitoring and diagnostic tools. These advantages are particularly important for software projects that involve processing large amounts of data distributed across server clusters, just like Davinci Care.

Within the Davinci Care project, we were able to make the most of the concept of application isolation. Before upgrading to the new package manager, there were dependency conflicts within the project. Application isolation prevented the dependencies of one application from interfering with those of another application within the same project. In a complex project like Davinci Care, with different applications or modules, this aspect brought a significant advantage. Application isolation also improved the performance of Yarn, as limiting the number of dependencies to consider during installation or updating made dependency management operations faster and made maintenance and updating of individual applications easier without affecting others.

Just as a cat chases its ball of yarn, we developers are required to chase and follow updates to our tools to keep up with rapid architectural changes, especially for applications that integrate with others. Nowadays, it wouldn’t make much sense to choose to upgrade to Yarn 2. On the contrary, it would make more sense to “jump” directly to Yarn 3 or wait for the official release of Yarn 4 because it seems to lay the foundation to prepare for the “future ESM.”

In light of the experience on the Davinci Care project, I can only hope that any software project, no matter how complex, can benefit from the technological advancement of such an important tool as Yarn. It’s unnecessary to remind that any version upgrade released always aims to improve what’s already been done. For this reason alone, one should always view the transition to a newer version of software tools with optimism and trust in the developers, but with a solid starting point. The perfect description of a great journey.

Safe travels to all!

--

--