pnpm add
Packages and runtimes
Usage
pnpm add [-D] [-w] <package>Puts the package in a shared store and links it into node_modules; at a workspace root pnpm refuses a plain add and wants -w or --filter to say where it goes.
Common flags
| Flag | Meaning |
|---|---|
| -D | devDependency |
| -g | global |
| -w | add it to the workspace root |
| --filter <pkg> | add it inside one workspace package |
| -E | exact version |
| --save-peer | peerDependency |
Examples
pnpm add -D vitestadds a dev dependency, linked from the shared store
pnpm add -w typescriptinstalls at the root of a workspace
pnpm add --filter web reactinstalls into the web package only
The question is always what goes where: inside this project, or on the whole machine.
How to read this
- Square brackets [ ] mark a part you may leave out.
- An ellipsis … means you can list more than one.
- Flags are case-sensitive — in some commands -r and -R do different things.
Questions
Q. What does pnpm add do?
Puts the package in a shared store and links it into node_modules; at a workspace root pnpm refuses a plain add and wants -w or --filter to say where it goes.
Q. How do I type it?
pnpm add [-D] [-w] <package> — square brackets mark the parts you can leave out.
Q. How many flags are worth knowing?
6 are listed here; the full set is in man pnpm. This command sits under Packages and runtimes.
Related commands
man page: man pnpm-add