Skip to content
BENIBIX Learn

Yarn

Development🛠️ Editors & ToolsPackages

Also known as Yarn Package Manager, yarn add, Yarn Berry

A tool that adds code packages to JavaScript apps. It is used in place of npm.

Think of it like

It is like a second shop on the same street. It sells the same toys, in its own way.

Example

Emma joins a team whose project has a yarn.lock file. She runs yarn install, not npm install, so she gets the same versions.

Why it matters

Many projects use it. You need to know which tool a project uses, or the installs will not match.

Definition

Yarn is a free package manager for JavaScript, used in place of npm. It fetches packages from the same npm registry. You add a package with yarn add, and it writes a lockfile called yarn.lock. Yarn came early with ideas like lockfiles and fast offline installs. Teams pick it for speed and for its tools for big projects made of many parts.

Example code

console
$ yarn add lodash
One command adds a package and writes its exact version to yarn.lock.
Yarn sits beside npm and pnpm. All three fetch from the npm registry.

Common mistake

Mixing Yarn and npm in one project. Each writes its own lockfile, and the two drift apart.

Key takeaways

  1. 1
    Same registry. It installs the packages npm does.
  2. 2
    Own lockfile. It writes yarn.lock, not package-lock.json.
  3. 3
    One tool per project. Do not mix it with npm.

Compare

Learn it properly