Skip to the workspace
Pebellslearn by building
Package Managers  ›  Capstone Project

npm, pnpm and Yarn

pnpm 13 minnpm, pnpm and Yarn all install from the same registry using package.json, differ in storage and commands, and each project should stick to the one its lockfile shows.

frontend / npm, pnpm and Yarn

Explore each scene at your own pace.

01 · The rule

The rule

npm, pnpm and Yarn

You open a new project and find pnpm-lock.yaml instead of package-lock.json. Another uses yarn.lock. These are not different ecosystems. They are three package managers installing from the same registry into the same kind of project, and switching between them is mostly a matter of reading which lockfile is present.

The rule

Same registry, same package.json; the lockfile tells you which manager to use.

All three read package.json, download packages from the npm registry and run the same scripts. They differ in how they store packages on disk and in a few commands.

npm pnpm Yarn
Comes with Node.js a separate install a separate install
Lockfile package-lock.json pnpm-lock.yaml yarn.lock
Install everything npm install pnpm install yarn
Add a package npm install date-fns pnpm add date-fns yarn add date-fns
Add a dev package npm install -D vite pnpm add -D vite yarn add -D vite
Run a script npm run dev pnpm dev yarn dev
Run a tool once npx pnpm dlx yarn dlx

npm is the default: always available wherever Node.js is, and perfectly fine for most projects.

pnpm keeps a single copy of each package version in one global store on your computer and links projects to it. Ten projects using the same library share one copy on disk, and installs are often faster. Its node_modules is also stricter: your code can only import packages you actually listed, which catches missing dependencies that npm would quietly allow.

Yarn was created when npm was slower and less predictable, and it introduced ideas npm later adopted, such as lockfiles and workspaces. Modern Yarn versions also offer a mode that skips node_modules entirely.

One project, one manager. Mixing managers in the same project creates two lockfiles that disagree, and installs stop being predictable. Many projects record their choice in package.json:

{
  "packageManager": "pnpm@9.12.0"
}

Node's Corepack tool can read that field and use the matching manager version automatically.

Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.