DEV Community

Cover image for Yarn: Facebook knitted a blanket for npm

Yarn: Facebook knitted a blanket for npm

skiilaa profile image skiilaa ・1 min read

Yarn is a package manager made by Facebook to replace npm. It's fast, easy and it doesn't have it's own registry.

The following post will be a guide for adding Yarn support to your project.

Using Yarn with your project

It's easy!

  1. Install Yarn.
  2. Run yarn in the directory of your project.
  3. Commit the generated yarn.lock file.

After that, you can easily add modules with yarn. And it's really fast.

Adding a dependency:

yarn add <dependency>
yarn add <dependency>@[version]
yarn add <dependency>@[tag]
Enter fullscreen mode Exit fullscreen mode

This automatically adds the dependency to your config.json

What is a Lockfile

A lockfile is made for the purpose of getting rid of the sentence "Works for me."

It stores the version of the package that the developer has, so when the user types "yarn", it installs the package with the version that the developer was coding for.

No more GitHub issues about dependencies!

Handy extras

The handiest extra command included in Yarn is the "why" sub-command.

yarn why <package>

It shows why a package is installed, for example:
"This module exists because it's specified in "dependencies"."


Editor guide