Set up a JavaScript monorepo
A monorepo holds many packages in one repository. Workspaces are the native feature in npm, Yarn, and pnpm that wires those packages together: they share one install, link local packages by name, and let you run scripts across the whole tree. This builder produces the exact workspace declaration for whichever manager you use.
How it works
For npm and Yarn, the configuration lives in the root package.json under a workspaces key. The simplest form is an array of glob patterns — each glob points at folders that each contain a package.json. Yarn additionally supports an object form with a nohoist array to keep certain dependencies inside individual packages instead of hoisting them to the root.
For pnpm, the configuration is a separate pnpm-workspace.yaml file with a packages list of the same glob patterns. pnpm reads this file to discover workspace members and create its content-addressable, symlinked node_modules.
The patterns are evaluated relative to the repo root. A glob like packages/* matches every immediate subfolder of packages. Each matched folder must contain its own package.json with a unique name, which becomes the import name other packages use.
Tips and notes
- Mark the root package
private: true— all three managers require it for workspaces. - Keep package names unique; that name is how sibling packages reference each other.
- Use
nohoist(Yarn) only when a tool breaks under hoisting, such as React Native. - After editing the config, run a fresh install so symlinks are created.