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, initialize projects, and get quick help.

Install pnpm with standalone script

Install pnpm via the official standalone script.

bashANYpnpminstallbootstrap
bash
curl -fsSL https://get.pnpm.io/install.sh | sh -

Install pnpm via the official standalone script.

Set up pnpm on your machine

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

bashANYpnpmsetupbootstrap
bash
pnpm setup

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

Initialize a package

Create a package.json interactively.

bashANYpnpminitpackage.json
bash
pnpm init

Create a package.json interactively.

Show pnpm help

Display top-level CLI help.

bashANYpnpmhelp
bash
pnpm help

Display top-level CLI help.

Show help for a command

Display help for a specific subcommand.

bashANYpnpmhelpdocs
bash
pnpm help add

Display help for a specific subcommand.

Show pnpm version

Print the installed pnpm version.

bashANYpnpmversion
bash
pnpm --version

Print the installed pnpm version.

Show Node.js version used by pnpm

Check the Node runtime in the current environment.

bashANYpnpmnodeenv
bash
pnpm exec node --version

Check the Node runtime in the current environment.

Install, Add, Remove, Update

Core package management commands.

Install all dependencies

Install dependencies from package.json and lockfile.

bashANYpnpminstalldeps
bash
pnpm install

Install dependencies from package.json and lockfile.

Install with frozen lockfile

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

bashANYpnpminstalllockfileci
bash
pnpm install --frozen-lockfile

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

Install in offline mode

Install using only already-fetched packages from the store.

bashANYpnpminstallofflinestore
bash
pnpm install --offline

Install using only already-fetched packages from the store.

Add dependency

Add a package to dependencies.

bashANYpnpmadddeps
bash
pnpm add lodash

Add a package to dependencies.

Add dev dependency

Add a package to devDependencies.

bashANYpnpmadddevDependencies
bash
pnpm add -D typescript

Add a package to devDependencies.

Add optional dependency

Add a package to optionalDependencies.

bashANYpnpmaddoptionalDependencies
bash
pnpm add -O fsevents

Add a package to optionalDependencies.

Add exact version

Save an exact version instead of a range.

bashANYpnpmaddversioning
bash
pnpm add react@18.3.1 --save-exact

Save an exact version instead of a range.

Remove dependency

Remove a package from dependencies.

bashANYpnpmremovedeps
bash
pnpm remove lodash

Remove a package from dependencies.

Update dependencies

Update dependencies according to the allowed ranges.

bashANYpnpmupdatedeps
bash
pnpm update

Update dependencies according to the allowed ranges.

Update package to latest

Update a package to the latest available version.

bashANYpnpmupdatelatest
bash
pnpm update react --latest

Update a package to the latest available version.

Dedupe lockfile

Reduce duplicates in the lockfile when possible.

bashANYpnpmdedupelockfile
bash
pnpm dedupe

Reduce duplicates in the lockfile when possible.

Import lockfile from npm or Yarn

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

bashANYpnpmimportmigration
bash
pnpm import

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

Run, Exec, and Inspect

Run scripts, binaries, and inspect dependency state.

Run a package script

Run a script from package.json.

bashANYpnpmrunscripts
bash
pnpm run build

Run a script from package.json.

Run script via shorthand

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

bashANYpnpmrunscripts
bash
pnpm test

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

Execute binary in project context

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

bashANYpnpmexecbinaries
bash
pnpm exec eslint .

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

Run one-off package

Download and run a package without permanently installing it.

bashANYpnpmdlxscaffold
bash
pnpm dlx create-vite@latest my-app

Download and run a package without permanently installing it.

List installed packages

Show installed packages in a tree structure.

bashANYpnpmlistinspect
bash
pnpm list

Show installed packages in a tree structure.

List top-level packages

Show only top-level dependencies.

bashANYpnpmlistinspect
bash
pnpm list --depth 0

Show only top-level dependencies.

Explain why a package is present

Show why a package is installed in the dependency graph.

bashANYpnpmwhyinspect
bash
pnpm why react

Show why a package is installed in the dependency graph.

Show outdated dependencies

List dependencies with newer versions available.

bashANYpnpmoutdatedinspect
bash
pnpm outdated

List dependencies with newer versions available.

Audit dependencies

Scan dependencies for known vulnerabilities.

bashANYpnpmauditsecurity
bash
pnpm audit

Scan dependencies for known vulnerabilities.

Attempt audit fixes

Try to apply non-breaking security updates automatically.

bashANYpnpmauditsecurityfix
bash
pnpm audit --fix

Try to apply non-breaking security updates automatically.

Print store path

Show the location of the content-addressable store.

bashANYpnpmstoreinspect
bash
pnpm store path

Show the location of the content-addressable store.

Filtering and Recursive Execution

Target specific workspace packages and run recursively.

Install across workspace

Run install recursively across workspace packages.

bashANYpnpmworkspacerecursive
bash
pnpm -r install

Run install recursively across workspace packages.

Run build in all workspace packages

Run a script recursively in all packages.

bashANYpnpmworkspacerecursivescripts
bash
pnpm -r run build

Run a script recursively in all packages.

Operate on one workspace package

Limit a command to a selected workspace package.

bashANYpnpmworkspacefilter
bash
pnpm --filter @acme/web test

Limit a command to a selected workspace package.

Filter package and dependents

Target a package and packages that depend on it.

bashANYpnpmworkspacefilterdependents
bash
pnpm --filter @acme/ui... build

Target a package and packages that depend on it.

Filter package and its deps

Target a package and its dependency chain.

bashANYpnpmworkspacefilterdependencies
bash
pnpm --filter ...@acme/api test

Target a package and its dependency chain.

Filter by directory

Target packages by path selector.

bashANYpnpmworkspacefilterpath
bash
pnpm --filter ./packages/web... lint

Target packages by path selector.

Run in parallel

Run a script in parallel across packages.

bashANYpnpmworkspaceparallel
bash
pnpm -r --parallel run dev

Run a script in parallel across packages.

Stream prefixed output

Stream real-time output from recursive runs.

bashANYpnpmworkspaceoutput
bash
pnpm -r --stream test

Stream real-time output from recursive runs.

Recommended next

No recommendations yet.