pnpm workspaces for a repo that holds more than one app
A pnpm workspace is a practical way to keep an API, a web app, and shared packages in one repo without installing the same dependency ten times.
When a project is one app, a single `package.json` is enough. The moment you have an API, a web app, and a shared library in the same repository, that single file starts to lie: test scripts get prefixes, dependencies get mixed, and a change in the UI can quietly break the server install.
I use pnpm workspaces for that shape of repo. This is a review of why, and when I would not.
What pnpm does well here
A workspace lets each package keep its own `package.json`, while one lockfile covers the whole tree. pnpm then links local packages to each other and stores downloaded packages in a content-addressable store, so two apps that need the same version of TypeScript do not each keep a full copy in `node_modules`.
The practical wins for me:
- Scripts stay close to the package they belong to. `pnpm --filter api test` is easier to read than a root script with a buried `cd`.
- You can bump a dependency in one package without pretending the others use it.
- The lockfile is strict. Accidental extra copies of a package show up as something you can inspect, not as a surprise at runtime.
npm can do workspaces too. I am not making a purity argument. I prefer pnpm's default linking model and the way it fails when a package uses something it did not declare. That failure is annoying for about ten minutes and useful for the rest of the year.
Where it is a poor fit
If the repo is one Express app and a README, a workspace is ceremony. Use a single package and move on.
If the packages in the repo are released on different schedules, with different public names, a workspace can still work, but you now have a publishing problem, not just an install problem. I would not pick pnpm workspaces just to avoid that. I would pick a clear release process first.
pnpm also has opinions about hoisting. Most of the time those opinions are what you wanted. The first time a tool expects a dependency to be sitting at the repo root, you will spend a little while fixing the install instead of the tool. That is a real cost. It is a smaller cost than discovering, months later, that two apps were type-checking against different copies of the same library.
How I judge it
I care about three questions:
1. Can a new clone run one install and then run each package's tests? 2. Can I change the API without reinstalling the web app by hand? 3. When a dependency is missing from a package, does the install fail in that package, or does it silently borrow a copy from a sibling?
pnpm workspaces answer those well enough that I start there for a multi-app TypeScript repo. I would look elsewhere if I needed a tool whose whole job is massive multi-language monorepos. For a Node API, a web client, and a couple of shared packages, this is the default I am happy to keep.