All cheatsheets

pnpm Cheat Sheet

Quick reference for pnpm: install / add / remove / update, scripts, workspaces, store & cache and config — focused on the GitHub-site pnpm repo workflow, with options and practical examples.

31 commands

Install & Manage

pnpm install

Install all dependencies declared in package.json, updating the lockfile as needed.

--frozen-lockfile (CI default in this repo); --prod; --offline; --ignore-scripts; --shamefully-hoist; --strict-peer-dependencies=false; --prefer-offline

pnpm install --frozen-lockfile
pnpm add <pkg>

Add a runtime dependency and write to package.json.

-D / --save-dev; -E / --save-exact; -O / --save-optional; -P / --save-prod; -g global; --workspace-root add at workspace root

pnpm add -D vitest @types/node
pnpm add -g <pkg>

Install a global tool (e.g. TypeScript, ESLint, tsx) onto the path.

-g; --global-prefix; --reporter append|ndjson

pnpm add -g typescript tsx
pnpm remove <pkg>

Remove a dependency from the project and the lockfile.

-D from devDependencies; -g from globals; --filter pkg remove from one workspace only

pnpm remove lodash && pnpm remove -F web -D @types/jest
pnpm update / pnpm update -L

Update dependencies within the semver range; -L / --latest upgrades to the newest version.

-L / --latest; -i / --interactive; --workspace-root; --filter

pnpm update -i vue && pnpm update -L @nuxt/i18n
pnpm outdated

Show outdated packages alongside current / wanted / latest versions.

--long; --recursive / -r; --filter

pnpm outdated -r --long
pnpm list

List installed packages and a tree of what depends on them.

--depth 0 only direct; --prod / --dev; -r recursive; --json | jq

pnpm list --depth 0 --prod | head -20
pnpm audit / pnpm audit --fix

Run the npm-style security advisory check against the lockfile.

--prod only production; --json

pnpm audit --json | jq '.metadata.vulnerabilities'
pnpm dedupe

Prune the lockfile/dependency tree by hoisting to a single version where possible.

--check; --strict-peer-dependencies=false

pnpm dedupe --check
pnpm rebuild

Rebuild native dependencies (post-build / after Node version bump).

--reporter; --recursive; --filter

pnpm rebuild -r && pnpm rebuild esbuild
pnpm approve-builds

Approve build scripts for native packages (e.g. esbuild, sharp, @swc/core).

interactive prompts; can also be set via package.json#pnpm.onlyBuiltDependencies

pnpm approve-builds --yes esbuild @parcel/watcher
pnpm import

Import an existing package-lock.json / yarn.lock into a pnpm-lock.yaml.

import; n/a other params

pnpm import --no-lockfile

Run & DX

pnpm run <script>

Run a script defined in package.json#scripts.

-r / --recursive run in every package; --filter / -F target one; --parallel; --no-color

pnpm run dev && pnpm -F src/www run build
pnpm dlx <pkg>

Fetch a package from the registry and run its binary without permanently installing.

dlx pkg args; --package extra pkg; --silent

pnpm dlx create-vite@latest my-app --template vue-ts && pnpm dlx vitest --run
pnpm exec <cmd>

Run a command in the project's context (PATH includes .node_modules/.bin).

exec ...; --filter target workspace; --recursive; --parallel

pnpm exec vitest run && pnpm exec -- tsc --noEmit -p src/www/tsconfig.json
pnpm create <name>

Scaffold a new project from a create-* style package.

create [name] [args]; -y / --yes

pnpm create nuxt my-app && cd my-app && pnpm install

Workspace

pnpm -r <cmd>

Recursive — run a pnpm action across every package in the workspace.

-r run build; --parallel; --topology sort; --order

pnpm -r --filter "./packages/**" run build --silent
pnpm --filter <pkg>

Target one package by name, directory, glob or ./relative-path.

--filter pkg | --filter ./packages/foo | --filter {pkg} strict name only; -F alias

pnpm --filter trowsoft-pdf-merge run build && pnpm -F "./packages/tools/*" outdated
pnpm add ... -w / --workspace-root

Add a hoisted dev dependency that's shared across the workspace.

-w / --workspace-root; -D to devDeps

pnpm add -Dw typescript

Store & Cache

pnpm store path

Print the location of pnpm's content-addressable store (deduped across projects).

store path; --virtual-store-dir DIR

pnpm store path && du -sh $(pnpm store path)
pnpm store prune

Remove unreferenced packages from the store (reduces disk usage).

store prune; --force skip prompt

pnpm store prune
pnpm cache list / cache delete

List or delete entries in pnpm's metadata cache.

cache list; cache delete <pkg>@<ver>; --registry

pnpm cache list vitest@latest

Config & Info

pnpm config get|set <key> [value]

Read or write to the user's/global/store/project pnpm config.

config get key; config set key val; --location project|user|global

pnpm config set registry https://registry.npmjs.org/ --location user && pnpm config get registry
pnpm config delete|list

List all effective config keys, or delete one.

config list --location project; config delete key

pnpm config list --location project
pnpm why <pkg>

Explain why a package is in node_modules — show the chain of dependants.

--prod; --dev; -r; --filter

pnpm why -r vue && pnpm why lodash -r
pnpm link / pnpm link --global

Symlink a local package into the current project, or install a global package locally.

link (uses ./); link --global <pkg>; --dir

cd packages/tools/foo && pnpm link --global && cd my-app && pnpm link --global foo

Publish & Pack

pnpm publish

Publish the current package to the configured registry.

--dry-run; --tag alpha|beta|next; --access public|restricted; --otp N; --filter

pnpm publish --dry-run --tag canary --access public
pnpm pack

Create a tarball of the package without publishing (for upload elsewhere).

--pack-gzip-level 0..9; --pack-destination DIR

pnpm pack --pack-destination ./release

Recurring Workflows

pnpm recursive list / pnpm -r why

Inspect the dependency tree across all workspaces at once.

pnpm recursive list --depth 0
pnpm run --filter <pkg> test

Run a script in just one workspace — perfect for fine-grained CI.

--filter with dependencies/dependents; --parallel

pnpm --filter "trowsoft-pdf-*" run build --parallel
pnpm sync:tools / pnpm build:tools

Repo helpers from this site — sync tool translations into the Nuxt app, then build tool bundles.

pnpm sync:tools && pnpm build:tools

Cheatsheet version 1.0.0

Covers pnpm 9+