Skip to content
Latchkey

yarn workspaces: Usage, Options & Common Errors

Run commands across a Yarn monorepo.

yarn workspace <name> runs a command in one workspace; yarn workspaces (with foreach in Berry) runs across all of them - the core of Yarn monorepo management.

What it does

yarn workspace <name> <cmd> runs a command in a single named workspace. In Berry, yarn workspaces foreach -A <cmd> runs across every workspace (with -pt for parallel, topological order). In Yarn 1, yarn workspaces run <cmd> runs a script in all workspaces.

Common usage

Terminal
yarn workspace @acme/web build           # one workspace
yarn workspaces foreach -A run build     # Berry: all workspaces
yarn workspaces foreach -pt run build    # parallel, topo order
yarn workspaces run test                 # Yarn 1: all workspaces

Common CI error: workspace not found

yarn workspace fails with "Workspace not found" because the name does not match a package.json name, or the workspaces globs in the root package.json do not include the folder. Use the package name field (not the directory), and confirm the root workspaces patterns cover it.

package.json
# root package.json:
"workspaces": ["packages/*", "apps/*"]

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →