← All notes

pnpm workspaces list projects in pnpm-workspace.yaml and link them with the workspace: protocol

Answer: Put a pnpm-workspace.yaml file in the repository root; its packages field lists the directories of the workspace's projects. Depend on sibling packages with "foo": "workspace:*" so pnpm refuses to resolve to anything other than a local workspace package.

Files

# pnpm-workspace.yaml
packages:
  - packages/*
{ "dependencies": { "foo": "workspace:*", "bar": "workspace:~", "qar": "workspace:^", "zoo": "workspace:^1.5.0" } }

Why the workspace: protocol

With linkWorkspacePackages set to true, pnpm links workspace packages only when they match the declared range; otherwise, for instance when foo@2.0.0 is not in the workspace, it installs foo@2.0.0 from the registry. This behavior introduces some uncertainty, which the workspace: protocol avoids: with "foo": "workspace:2.0.0", installation will fail. A relative spec such as "foo": "workspace:../foo" also works.

What publishing does

When a package is packed by pnpm pack or a publish command such as pnpm publish, each workspace: dependency is replaced dynamically. workspace:, workspace:~ and workspace:^ become the target package's version (with ~ or ^ kept), and other ranges become the associated semver range. If all packages are at version 1.5.0, the example above is transformed into 1.5.0, ~1.5.0, ^1.5.0 and ^1.5.0. A bare workspace: without a range is treated as workspace:.

Migrating from npm, Yarn or Bun

Since v12.7.0, if the root package.json has a workspaces field and there is no pnpm-workspace.yaml, pnpm install creates one with the same patterns. Only pnpm-workspace.yaml is read afterwards.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: pnpm docs, Workspace; pnpm/pnpm.io (GitHub), Workspace (source page). MIT (https://raw.githubusercontent.com/pnpm/pnpm.io/main/LICENSE). Copyright pnpm contributors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: pnpm docs, Workspace; pnpm/pnpm.io (GitHub), Workspace (source page). MIT (https://raw.githubusercontent.com/pnpm/pnpm.io/main/LICENSE). Copyright pnpm contributors.

Cite this

Permanent ID: iil:note:cs3dngbb

iinventedlight. 2026. "pnpm workspaces list projects in pnpm-workspace.yaml and link them with the workspace: protocol." iinventedlight Library, iil:note:cs3dngbb, version of 2026-11-18. https://iinventedlight.com/library/notes/pnpm-workspaces/. License: CC-BY-4.0.

@misc{iil_note_cs3dngbb,
  author = {{iinventedlight}},
  title = {{pnpm workspaces list projects in pnpm-workspace.yaml and link them with the workspace: protocol}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-18},
  url = {https://iinventedlight.com/library/notes/pnpm-workspaces/},
  note = {Permanent ID iil:note:cs3dngbb. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/pnpm-workspaces.md.