Click any command to expand the explanation and examples.
π¦ Install & Manage Packages
pnpm install / add / remove basics
# Install all dependencies pnpm install pnpm i # ShorthandAdd a package
pnpm add express pnpm add -D typescript # Dev dependency pnpm add -g nodemon # Global
Remove
pnpm remove express pnpm rm express # Shorthand
Update
pnpm update pnpm update express # Specific package pnpm update βlatest # Ignore semver ranges
Check outdated
pnpm outdated
npm β pnpm translation migrate
# npm β pnpm npm install β pnpm install npm install express β pnpm add express npm install -D jest β pnpm add -D jest npm uninstall express β pnpm remove express npm run build β pnpm build (or pnpm run build) npm test β pnpm test npx create-next-app β pnpm create next-app npm ci β pnpm install --frozen-lockfile npm cache clean --force β pnpm store prune
βΆοΈ Scripts
pnpm run / exec scripts
# Run a script from package.json pnpm run build pnpm build # Shorthand (no "run" needed) pnpm dev pnpm testRun a binary from node_modules
pnpm exec eslint src/ pnpm dlx create-next-app # Like npx (download and run)
Pass args to scripts
pnpm test β βwatch pnpm build β βmode production
ποΈ Workspaces (Monorepo)
Workspace setup and commands workspace
# pnpm-workspace.yaml (in repo root) packages: - 'apps/*' - 'packages/*'Structure:
my-monorepo/
pnpm-workspace.yaml
apps/
web/package.json
api/package.json
packages/
shared/package.json
ui/package.json
# Run command in specific workspace pnpm --filter web dev pnpm --filter api build # Run in all workspaces pnpm -r build pnpm -r test # Add dependency to specific workspace pnpm --filter web add react # Add workspace package as dependency pnpm --filter web add @myorg/shared --workspace # Install all workspaces pnpm install
π§ Configuration
.npmrc settings for pnpm config
# .npmrc # Auto-install peers (recommended) auto-install-peers=trueHoist to root node_modules (needed for some tools)
shamefully-hoist=true
Strict peer dependencies
strict-peer-dependencies=false
Use specific Node version
use-node-version=20.11.0
Store management config
# Show store path pnpm store pathClean unused packages from store
pnpm store prune
Check store status
pnpm store status
β‘ Why pnpm?
pnpm vs npm vs yarn comparison
# Disk space: pnpm stores packages once, links them # npm: each project gets its own copy of every package # pnpm: one copy shared across all projectsSpeed: pnpm is faster because it links instead of copying
npm install: ~30s (typical project)
pnpm install: ~10s (same project)
Strictness: pnpm doesnβt hoist by default
This means you canβt accidentally import packages
you didnβt declare as dependencies (phantom dependencies)