pnpm provides rich CLI commands to manage dependencies and projects.
Installation Commands:
bash# Install all dependencies pnpm install pnpm i # Install single package pnpm add lodash pnpm add lodash@4.17.21 # Install to different dependency types pnpm add lodash --save-prod # dependencies (default) pnpm add lodash --save-dev # devDependencies pnpm add lodash --save-optional # optionalDependencies pnpm add lodash -D # devDependencies shorthand pnpm add lodash -O # optionalDependencies shorthand # Global installation pnpm add -g lodash pnpm add --global lodash
Update Commands:
bash# Update single package pnpm update lodash pnpm up lodash # Update all dependencies pnpm update pnpm up # Update to latest version pnpm update --latest pnpm up -L # Interactive update pnpm update --interactive pnpm up -i
Remove Commands:
bash# Remove package pnpm remove lodash pnpm rm lodash # Remove multiple packages pnpm remove lodash express # Remove global package pnpm remove -g lodash
Run Scripts:
bash# Run scripts in package.json pnpm run build pnpm run test # Shorthand pnpm build pnpm test # Pass arguments pnpm build -- --watch
Monorepo Related Commands:
bash# Run command in specific package pnpm --filter <package-name> build pnpm -F <package-name> build # Run in all packages pnpm -r build # Parallel execution pnpm -r --parallel build # Run only in changed packages pnpm -r --filter "...[origin/main]" build # Recursive command execution pnpm -r exec rm -rf node_modules
Query Commands:
bash# View package information pnpm info lodash pnpm view lodash # View installed packages pnpm list pnpm ls # View globally installed packages pnpm list -g # View dependency tree pnpm list --depth=2 # View outdated packages pnpm outdated
Store Management Commands:
bash# View store path pnpm store path # Clean store pnpm store prune # Verify store pnpm store verify
Other Common Commands:
bash# Create project pnpm create react-app my-app pnpm create vite # Execute package command pnpm dlx create-react-app my-app # Import other lock files pnpm import # Link local package pnpm link ../local-package # Check dependency issues pnpm audit # Why is this package installed pnpm why lodash
Configuration Commands:
bash# View configuration pnpm config list # Set configuration pnpm config set store-dir /path/to/store # Delete configuration pnpm config delete store-dir
Command Comparison:
| npm | yarn | pnpm |
|---|---|---|
| npm install | yarn | pnpm install |
| npm add lodash | yarn add lodash | pnpm add lodash |
| npm run build | yarn build | pnpm build |
| npm update | yarn upgrade | pnpm update |
| npm remove lodash | yarn remove lodash | pnpm remove lodash |