Update: This post is based on using Yarn 1. A major update Yarn 2
In the comments of my post about things I do everytime I start a Gatsby site, there was a really good comment asking why I switch the scripts from npm to Yarn. Great question, different topic, so I wrote this post to share a few reasons I switched.
Historically, the npm CLI is the most common tool for managing dependencies and scripting in a node project. But, there are other CLIs that expect the same package.json schema, for example Yarn or pnpm.
But, I think it's important to support alternative package managers like Yarn. Yarn and npm default to npm's registry, but also support alternative package registries. I think these problems will be solved with more decentralized registries and multiple CLIs like Yarn.
Anyway, that aside, I think Yarn is very good software for a few reasons.
Honestly, this was the first reason I started using Yarn. If package.json has a registered script called "build" you can run it with npm like this:
npm run build
Or with Yarn:
Small difference, but I think the time savings adds up. Simpler is better.
Got a project that is pinned to a bunch of out of date dependencies? While have I got the CLI command for you. Yarn's upgrade-interactive is the hottest command in automated upgrades.
To upgrade one, some or all of your dependencies to the latest version.To bring up a set of prompts to determine which dependencies to upgrade, just type:
yarn upgrade-interactive --latest
Make your selections and watch it install.
Monorepos allow you to develop multiple packages in one git repo. If the packages are related or fairly interdependent, this can speed up development. Depending on the needs, I like to do this with Yarn workspaces or Yarn workspaces and Lerna.
A yarn workspace is a folder in your package with its own package.json. you can use the workspace command to run a script
I've experienced less frustration with dependency resolution, and other errors since switching to Yarn. Also, it makes working with monorepos easier, for me.
Have you switched? If so, did you have a different reason? Disagree? Comments section is below 👇 or @ me on Twitter.