Skip to main content

What are pnpm workspaces?

pnpm workspaces are a mechanism that lets you combine several related projects (packages) into one shared repository (a monorepo) and manage their dependencies centrally. This is convenient when a single repo holds several packages, libraries, or services that share dependencies or depend on each other.


Problems workspaces solve

  1. Unified dependency management Shared packages are installed once, not in every project.
  2. Linking packages locally to each other A package can depend on another package in the same repository without publishing it to npm, pnpm creates the local link automatically.
  3. Optimized installation Installing all dependencies for all packages happens with one command, fast and without duplication.
  4. Convenience for large projects and monorepos Suits frontend, backend, libraries, and CLIs inside a single repo.

Example workspace structure

javascript
my-monorepo/ pnpm-workspace.yaml packages/ app/ package.json ui/ package.json

The pnpm-workspace.yaml file:

yaml
packages: - "packages/*"

How it is used

ActionCommand
Install dependencies for all packagespnpm install
Run a script in one packagepnpm --filter app dev
Add a dependency to a specific packagepnpm add react --filter app

Summary

pnpm workspaces are a tool for working with monorepos that lets you efficiently manage several packages in one repo, share dependencies, speed up installation, and easily link local packages together.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.