C.W.K.
Stream
Lesson 03 of 05 · published

Daily pnpm Commands

~12 min · pnpm, commands, workflow

Level 0Newbie
0 XP0/55 lessons0/16 achievements
0/80 XP to next level80 XP to go0% complete

pnpm's CLI mirrors npm's enough that most muscle memory transfers, with a few intentional improvements.

pnpm add <pkg> adds a runtime dep. pnpm add -D <pkg> adds a dev dep. pnpm remove <pkg> removes one. pnpm install with no args installs everything from the lockfile. pnpm install --frozen-lockfile is pnpm's npm ci equivalent — strict, fast, and the right command for CI.

pnpm <script> runs scripts directly — no run needed. pnpm build works as shorthand for pnpm run build. Less typing, fewer gotchas.

pnpm dlx <tool> is pnpm's npx — runs a tool without installing it. pnpm dlx create-vite my-app is the new npx create-vite my-app.

pnpm store manages the global content-addressable store. pnpm store path shows where it lives; pnpm store status reports health; pnpm store prune deletes packages no project references anymore.

pnpm why <pkg> answers 'why is this in my dependency tree?' — the most useful debugging command for sprawling lock files.

Code

Daily commands — npm-shaped, pnpm-flavored·bash
# Add / remove
pnpm add express
pnpm add -D vitest typescript
pnpm remove express

# Install everything
pnpm install

# CI install (npm ci equivalent)
pnpm install --frozen-lockfile

# Run scripts (no 'run' needed)
pnpm build
pnpm test
pnpm dev

# Run a tool without installing
pnpm dlx create-vite my-app
Store + dependency debugging·bash
# Where does the global content-addressable store live?
pnpm store path

# Health check
pnpm store status

# Reclaim disk by deleting packages no project references
pnpm store prune

# Why is this package in my tree?
pnpm why react
pnpm why -r react       # search across all workspaces
Migrate from npm·bash
# In an existing npm-managed project (has package-lock.json)
pnpm import          # converts package-lock.json -> pnpm-lock.yaml
rm package-lock.json # remove the old lockfile
rm -rf node_modules  # clear the old install
pnpm install         # fresh install via pnpm

External links

Exercise

Convert a small npm project to pnpm: run 'pnpm import', delete package-lock.json + node_modules, run 'pnpm install'. Compare the size of node_modules before and after. Then run 'pnpm why <some-deep-dep>' to see the dependency chain.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.