Skip to main content

pnpm Most Important Commands

A quick reference of the pnpm commands you reach for every day.

Install everything​

BASH
pnpm install

Equivalent:

BASH
pnpm i

In CI:

BASH
pnpm install --frozen-lockfile

This fails if pnpm-lock.yaml is out of sync.

Add dependency​

BASH
pnpm add react

Dev dependency:

BASH
pnpm add -D typescript

Global package:

BASH
pnpm add -g vercel

Add to workspace root:

BASH
pnpm add -w -D typescript

Remove dependency​

BASH
pnpm remove lodash

Alias:

BASH
pnpm rm lodash

Run scripts​

BASH
pnpm dev
pnpm build
pnpm test

Or explicitly:

BASH
pnpm run dev

pnpm run executes scripts from package.json. (pnpm)

Execute local binaries​

BASH
pnpm exec vite
pnpm exec eslint .

pnpm exec runs commands in the project context and adds node_modules/.bin to PATH. (pnpm)

Run a package without installing it permanently​

BASH
pnpm dlx create-vite
pnpm dlx shadcn@latest init

pnpm dlx fetches a package temporarily and runs its exposed binary. (pnpm)

Update dependencies​

BASH
pnpm update

Interactive upgrade:

BASH
pnpm update --interactive

Latest versions:

BASH
pnpm update --latest

List dependencies​

BASH
pnpm list

Why is this package installed?

BASH
pnpm why react

Clean/store commands​

Show store path:

BASH
pnpm store path

Prune unused packages from store:

BASH
pnpm store prune

Workspace filtering​

Run command only for one package:

BASH
pnpm --filter @acme/web build

Run tests for package and dependencies:

BASH
pnpm --filter @acme/web... test

Run for packages changed since branch:

BASH
pnpm --filter "...[origin/main]" test

This is extremely useful in monorepos.