Home·Terminal commands

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

FlagMeaning
-DdevDependency
-gglobal
-wadd it to the workspace root
--filter <pkg>add it inside one workspace package
-Eexact version
--save-peerpeerDependency

Examples

pnpm add -D vitest

adds a dev dependency, linked from the shared store

pnpm add -w typescript

installs at the root of a workspace

pnpm add --filter web react

installs 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