EMZETT.
Login

pnpm and Yarn compared with npm

In short: pnpm and Yarn are alternatives to npm as a JavaScript package manager. pnpm mainly saves space and time, Yarn offers its own workspaces and Plug’n’Play.

In more detail: All three read package.json, install from the same registry and produce a lock file, but differ in folder layout.

In Depth

  • npm: Ships with Node.js. Places packages flat in node_modules, each project gets its own copies.
  • pnpm: Stores each package only once globally and links it via hard links. This saves disk, speeds up installs and prevents “phantom dependencies”, imports of packages you never declared.
  • Yarn: Classic (v1) similar to npm, modern (Berry) with Plug’n’Play, which replaces node_modules and loads packages from archives.
  • Lock files: package-lock.json, pnpm-lock.yaml, yarn.lock. See lock files.
  • Monorepos: All three support workspaces. pnpm is especially popular for this.
  • Choice: Stay with the existing tool in existing projects, for new ones pnpm is a good pick.

See also: npm audit