pnpm Cheat Sheet

Comprehensive pnpm CLI reference for installs, dependency management, scripts, filtering, and inspection.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Getting Started
Install pnpm with standalone script
curl -fsSL https://get.pnpm.io/install.sh | sh -

# Install pnpm via the official standalone script.

Set up pnpm on your machine
pnpm setup

# Creates the pnpm home directory and updates shell configuration as needed.

Initialize a package
pnpm init

# Create a package.json interactively.

Show pnpm help
pnpm help

# Display top-level CLI help.

Show help for a command
pnpm help add

# Display help for a specific subcommand.

Show pnpm version
pnpm --version

# Print the installed pnpm version.

Show Node.js version used by pnpm
pnpm exec node --version

# Check the Node runtime in the current environment.

## Install, Add, Remove, Update
Install all dependencies
pnpm install

# Install dependencies from package.json and lockfile.

Install with frozen lockfile
pnpm install --frozen-lockfile

# Fail if the lockfile would need changes; common in CI.

Install in offline mode
pnpm install --offline

# Install using only already-fetched packages from the store.

Add dependency
pnpm add lodash

# Add a package to dependencies.

Add dev dependency
pnpm add -D typescript

# Add a package to devDependencies.

Add optional dependency
pnpm add -O fsevents

# Add a package to optionalDependencies.

Add exact version
pnpm add react@18.3.1 --save-exact

# Save an exact version instead of a range.

Remove dependency
pnpm remove lodash

# Remove a package from dependencies.

Update dependencies
pnpm update

# Update dependencies according to the allowed ranges.

Update package to latest
pnpm update react --latest

# Update a package to the latest available version.

Dedupe lockfile
pnpm dedupe

# Reduce duplicates in the lockfile when possible.

Import lockfile from npm or Yarn
pnpm import

# Generate pnpm-lock.yaml from package-lock.json, npm-shrinkwrap.json, or yarn.lock.

## Run, Exec, and Inspect
Run a package script
pnpm run build

# Run a script from package.json.

Run script via shorthand
pnpm test

# Run a script without typing run when there is no command ambiguity.

Execute binary in project context
pnpm exec eslint .

# Run a locally installed binary without adding it to PATH manually.

Run one-off package
pnpm dlx create-vite@latest my-app

# Download and run a package without permanently installing it.

List installed packages
pnpm list

# Show installed packages in a tree structure.

List top-level packages
pnpm list --depth 0

# Show only top-level dependencies.

Explain why a package is present
pnpm why react

# Show why a package is installed in the dependency graph.

Show outdated dependencies
pnpm outdated

# List dependencies with newer versions available.

Audit dependencies
pnpm audit

# Scan dependencies for known vulnerabilities.

Attempt audit fixes
pnpm audit --fix

# Try to apply non-breaking security updates automatically.

Print store path
pnpm store path

# Show the location of the content-addressable store.

## Filtering and Recursive Execution
Install across workspace
pnpm -r install

# Run install recursively across workspace packages.

Run build in all workspace packages
pnpm -r run build

# Run a script recursively in all packages.

Operate on one workspace package
pnpm --filter @acme/web test

# Limit a command to a selected workspace package.

Filter package and dependents
pnpm --filter @acme/ui... build

# Target a package and packages that depend on it.

Filter package and its deps
pnpm --filter ...@acme/api test

# Target a package and its dependency chain.

Filter by directory
pnpm --filter ./packages/web... lint

# Target packages by path selector.

Run in parallel
pnpm -r --parallel run dev

# Run a script in parallel across packages.

Stream prefixed output
pnpm -r --stream test

# Stream real-time output from recursive runs.

Recommended next

No recommendations yet.