This is an alpha, sneak peek of Monorepo Maestros. For this iteration, I'm getting all of my thoughts down. In the future, we'll have better information architecture, graphics, and other awesomeness. Your feedback is welcome!

pnpm

pnpm is a package manager built with an emphasis on monorepos. This makes it our preferred choice in a monorepo for a few specific reasons:

Setting up workspaces

To create your workspaces, make a file in the root of your repository called pnpm-workspace.yaml and add the globs where your workspaces will be located:

pnpm-workspace.yaml
packages:
- apps/*
- packages/*
- tooling/*
pnpm-workspace.yaml
packages:
- apps/*
- packages/*
- tooling/*

Note that you pnpm will let you add nested workspaces using a /** double star syntax but Turborepo does not currently support this feature.

If you're using Turborepo, you'll also need to add a line to your root package.json:

package.json
{
"name": "my-repo",
"private": true,
"scripts": { ... },
"devDependencies": { ... },
"packageManager": "pnpm@8.5.0"
}
package.json
{
"name": "my-repo",
"private": true,
"scripts": { ... },
"devDependencies": { ... },
"packageManager": "pnpm@8.5.0"
}

Migrating to pnpm

If you're migrating to pnpm from a different package manager, you may find that your repository starts to throw errors about not being able to find dependencies in certain workspaces.

It is very unlikely that you've found a bug in pnpm. Rather, pnpm may be finding a bug in your code.

Because pnpm resolves dependencies more strictly, you might have to do some debugging to learn why your dependencies are not being resolved. Common reasons include:

Tips and tricks

Bump an external package version in all workspaces

You'll often want to keep the same version of an external package consistent across your repository. For instance, you only have one version of React being used in your ui and web packages. Use this command to bump to the latest React version in all your workspaces:

Terminal
pnpm -r up react@latest
Terminal
pnpm -r up react@latest

You can change the package and version tag that you're targeting to your liking!

Figure out where a package is being installed

Package dependencies trees can be hard to debug. Sometimes, you just want to figure out what a package is in your repository in the first place.

Terminal
pnpm why react
Terminal
pnpm why react

This command will show you everywhere in your dependency tree where react is being brought in and why.