lerna vs pnpm vs yarn
Monorepo Management and Dependency Installation Strategies
lernapnpmyarnSimilar Packages:

Monorepo Management and Dependency Installation Strategies

pnpm and yarn are modern package managers that handle dependency installation, lockfile generation, and workspace linking for monorepos. lerna is a specialized tool focused on versioning, changelog generation, and publishing multiple packages from a single repository. While pnpm and yarn have replaced lerna for dependency installation, lerna remains relevant for managing release cycles. Choosing the right combination depends on whether you need strict dependency control, Plug'n'Play support, or automated publishing workflows.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
lerna036,0898.95 MB30810 days agoMIT
pnpm034,40218.9 MB2,13913 days agoMIT
yarn041,5285.34 MB2,0662 years agoBSD-2-Clause

Monorepo Management: Lerna vs pnpm vs Yarn

Managing a repository with multiple packages requires tools that handle dependency installation, linking, and versioning. pnpm and yarn are package managers that install dependencies and link workspaces. lerna is a tool specifically designed to version and publish those packages. While their roles overlap historically, modern workflows often combine them. Let's compare how they handle core engineering tasks.

📦 Dependency Installation & Storage

pnpm uses a content-addressable storage system.

  • Packages are stored once in a global store and linked to projects.
  • Saves significant disk space and speeds up installation.
// pnpm: .pnpmfile.cjs or default behavior
// No special config needed for store
// Installation command:
// pnpm install

yarn stores packages in a cache and links them to node_modules.

  • In Berry (v2+), it supports Plug'n'Play which removes node_modules entirely.
  • Traditional mode behaves similarly to npm but with better caching.
// yarn: .yarnrc.yml
nodeLinker: node-modules
# Installation command:
# yarn install

lerna does not install dependencies in modern versions.

  • It relies on pnpm or yarn for installation.
  • Historically used lerna bootstrap, but this is now deprecated.
// lerna: lerna.json
{
  "version": "independent",
  "npmClient": "pnpm"
}
// Installation command (delegated):
// pnpm install

🗂️ Workspace Configuration

pnpm requires a explicit workspace config file.

  • You define package locations in pnpm-workspace.yaml.
  • Supports the workspace: protocol for local dependencies.
# pnpm: pnpm-workspace.yaml
packages:
  - "packages/*"
  - "apps/*"

yarn defines workspaces directly in package.json.

  • You list glob patterns under the workspaces key.
  • Simpler setup for smaller monorepos.
// yarn: package.json
{
  "workspaces": [
    "packages/*",
    "apps/*"
  ]
}

lerna uses lerna.json to define package locations.

  • It scans these folders to manage versioning and scripts.
  • Does not handle linking itself anymore.
// lerna: lerna.json
{
  "packages": [
    "packages/*",
    "apps/*"
  ],
  "version": "independent"
}

🏃 Running Scripts Across Packages

pnpm uses the -r flag to run scripts recursively.

  • Runs a command in every package that has that script.
  • Fast and respects dependency spares dependencies.
# pnpm: Run build in all packages
pnpm -r run build

yarn uses the workspaces foreach command.

  • Allows filtering by name or path.
  • Flexible but slightly more verbose syntax.
# yarn: Run build in all packages
yarn workspaces foreach -A run build

lerna uses lerna run to execute scripts.

  • Can scope to specific packages using --scope.
  • Often used for complex task pipelines.
# lerna: Run build in all packages
lerna run build --stream

🚀 Versioning and Publishing

pnpm relies on external tools like Changesets.

  • Does not have built-in versioning commands.
  • Requires setup for automated releases.
# pnpm: Using Changesets
pnpm changeset version
pnpm changeset publish

yarn also relies on external tools like Changesets.

  • Similar workflow to pnpm for version management.
  • Integrates well with Yarn's plugin system.
# yarn: Using Changesets
yarn changeset version
yarn changeset publish

lerna has built-in versioning and publishing commands.

  • Handles bumping versions, updating changelogs, and publishing.
  • Supports fixed or independent versioning modes.
# lerna: Built-in versioning
lerna version
lerna publish

📊 Summary Table

Featurepnpmyarnlerna
Primary RolePackage ManagerPackage ManagerVersioning Tool
Install Commandpnpm installyarn installN/A (Delegate)
Workspace Configpnpm-workspace.yamlpackage.jsonlerna.json
Run Scriptspnpm -ryarn workspaces foreachlerna run
VersioningExternal (Changesets)External (Changesets)Built-in (lerna version)
Disk Efficiency⭐⭐⭐ (Hard links)⭐⭐ (Cache)N/A

💡 The Big Picture

pnpm is the top choice for installation and workspace management.

  • It saves disk space and prevents dependency issues.
  • Best paired with lerna for publishing or Changesets for versioning.

yarn is a strong alternative with unique features.

  • Choose it if you want Plug'n'Play or prefer its plugin ecosystem.
  • Also pairs well with lerna for release management.

lerna solves the release problem, not the install problem.

  • Use it to manage versions across many packages easily.
  • Do not use it for dependency installation in new projects.

Final Thought: For most modern monorepos, use pnpm for installation and workspaces. Add lerna only if you need its specific versioning and publishing features. If you prefer yarn, the same logic applies — use it for installs and add lerna for releases if needed.

How to Choose: lerna vs pnpm vs yarn

  • lerna:

    Choose lerna if you need automated versioning and publishing across multiple packages in a monorepo. It is best used alongside pnpm or yarn for installation, while lerna handles the release logic. It fits teams managing many libraries that need synchronized or independent version bumps.

  • pnpm:

    Choose pnpm if you prioritize disk space efficiency and installation speed in a monorepo. It uses a content-addressable storage system that prevents duplicate packages across projects. It is ideal for teams that want strict dependency isolation to avoid missing declarations in package.json.

  • yarn:

    Choose yarn if you need Plug'n'Play (PnP) support or prefer the Berry ecosystem features. It offers strong workspace management and deterministic installs without requiring node_modules hoisting in PnP mode. It suits projects that want to move away from traditional module resolution.

README for lerna

Lerna

Lerna is a fast, modern build system for managing and publishing multiple JavaScript/TypeScript packages from the same repository.

NPM Status CI Status

Usage

Check out our docs site here.