On its initial release, taking a wait-and-see approach with Yarn 2 may have been the correct call, but I’m here to tell you that it’s time to reconsider that decision. Here are three reasons you might have waited to make the switch — and why those reasons are out of date in 2021.
1. Backwards Compatibility with node_modules
However, Yarn 2 now offers an option that copies packages to the node_modules/ folder just like Yarn 1, providing backward compatibility for these projects. It literally requires adding a single line to your new
.yarnrc.yml configuration file to turn on this feature.
And of course, if you aren’t working on a React Native, Flow, or VSCE package project, this likely isn’t even an issue. The list of popular frontend JS tools that natively support PnP is long and growing.
2. Difficulty Migrating from Yarn 1.x
The PnP incompatibilities that plagued the initial Yarn 2 release — and the seismic shift it created in getting rid of that hefty node_modules/ folder — also meant migration could be a big pain for pre-existing projects. But with node_modules/ support added back in, Yarn 2 now provides a clean migration path. There are a not-insignificant number of steps here, especially if you’re moving to PnP support, but the documentation is clear and easy to follow. It shouldn’t actually be that difficult to undertake.
Also, if you’re starting a brand new project, migration isn’t a concern at all.
3. But My Yarn 1.X Setup Isn’t Broken!
Sorry Marge, the mob has spoken. As the Yarn 2 documentation mentions:
Even if you don’t use Plug’n’Play nor plan to use it, your project will still benefit from more stable node_modules layouts, improved performances, improved user experience, active development, and many other boons.
This is no different from other popular libraries or frameworks making huge architectural changes (think React 16.8 with hooks or Python 3). The longer you wait to make the switch, the more painful it will be for your project when you finally do. And in the meantime, you’ll be missing out on valuable improvements to a fundamental part of the workflow of every single project you work on.
A Future Without node_modules
There are plenty of other reasons to be excited about Yarn 2:
- Workspaces make monorepo-style projects more manageable. (Yeah, npm 7 has these too, but Yarn 2’s implementation is more expressive.)
- Constraints for dependencies across workspaces. This feature is still experimental but powerful!
Most importantly, though, I believe we’re going to look back on Yarn 2 as the beginning of the end of the node_modules/ folder, and I couldn’t be more excited about it.
The Yarn project started out to fix some of the fundamental issues that plagued early npm projects: non-deterministic package trees, inconsistent installs across different dev environments, and slow installs with extensive package dependencies. Yarn 2’s PnP feature feels like the logical conclusion of that mission, literally eliminating the folder at the root of the problem.
As we like to say in software development: the best time to update your software was the last LTS release; the second-best time is today. What are you waiting for?