Skip to content

How to understand a pnpm workspaces codebase

pnpm workspaces let several packages live in one repository and depend on each other through `workspace:` versions. There may be no extra build tool; scripts are run across packages with `pnpm -r` or `--filter`.

How to tell it's pnpm workspaces

  • pnpm-workspace.yaml and a pnpm-lock.yaml at the root
  • Dependencies like "@scope/utils": "workspace:*"
  • Root scripts using pnpm -r or pnpm --filter

Where things usually live

pnpm-workspace.yaml
Package globs and, optionally, version catalogs.
packages/*
Workspace packages, each with its own package.json.
package.json (root)
Shared dev tooling and scripts.
.npmrc
Settings such as hoisting and peer dependency behaviour.

Conventions, not rules. Real projects rename and move things, so confirm against the repository.

Where to start reading

  1. pnpm-workspace.yaml, to list packages
  2. Each package's package.json exports, main and scripts

How a request moves through the code

  1. 1pnpm install links workspace packages into each other's node_modules.
  2. 2A package imports another by name and gets the local folder.
  3. 3pnpm -r build runs builds across packages in dependency order.
  4. 4On publish, workspace: versions are replaced with real version numbers.

Questions to ask about the repository

  • Which packages depend on which?
  • Which packages are published and which are private?
  • Are dependency versions centralised in a catalog?

What trips people up

  • pnpm doesn't hoist dependencies by default, so code that relies on undeclared dependencies breaks; that's usually the fix, not a pnpm bug.
  • Packages consumed as TypeScript source need the consumer's build to compile them.