WORLDBOOK

pnpm | Worldbooks | WebMCP | Search | Submit

pnpm

Category: Unknown Author: Unknown Version: 1.0.0 Updated: Unknown
0

pnpm

Website: https://pnpm.io CLI Tool: pnpm Authentication: npm login

Description

pnpm (performant npm) is a fast, disk space efficient package manager for Node.js. It uses a content-addressable filesystem to store packages and creates hard links instead of copying files. Up to 2x faster than npm and saves significant disk space in monorepos.

Commands

Package Installation

Install Dependencies

pnpm install
pnpm i
pnpm install --frozen-lockfile
pnpm install --prefer-offline

Install all dependencies from package.json.

Add Package

pnpm add <package>
pnpm add react
pnpm add lodash@4.17.21
pnpm add <package> --save-dev
pnpm add <package> -D
pnpm add <package> --save-optional
pnpm add <package> --global

Add package to dependencies.

Install Specific Version

pnpm add <package>@<version>
pnpm add react@18.2.0
pnpm add <package>@latest
pnpm add <package>@next

Install specific version or tag.

Remove Package

pnpm remove <package>
pnpm rm <package>
pnpm remove react
pnpm remove <package> --global

Remove package from dependencies.

Update Packages

pnpm update
pnpm up
pnpm update <package>
pnpm update --latest
pnpm update --interactive

Update dependencies to latest versions.

List Packages

pnpm list
pnpm ls
pnpm list --depth 0
pnpm list <package>
pnpm list --global

List installed packages.

Scripts

Run Script

pnpm run <script>
pnpm run build
pnpm run test
pnpm run dev

Execute package.json script.

Special Scripts

pnpm start
pnpm test
pnpm run

Run without 'run' keyword or list all scripts.

Workspace Management

Install Workspace

pnpm install -r
pnpm install --recursive

Install in all workspace packages.

Add to Workspace

pnpm add <package> --filter <workspace>
pnpm add lodash --filter @myorg/utils
pnpm add <package> -w

Add package to specific workspace or root.

Run in Workspace

pnpm --filter <workspace> <command>
pnpm --filter @myorg/app build
pnpm -F <pattern> test

Run command in specific workspace.

Recursive Commands

pnpm -r run build
pnpm -r test
pnpm -r exec rm -rf dist

Run command in all workspaces.

Publishing

Publish Package

pnpm publish
pnpm publish --access public
pnpm publish --tag beta
pnpm publish --dry-run

Publish package to registry.

Version Bump

pnpm version patch
pnpm version minor
pnpm version major
pnpm version 1.2.3

Bump package version.

Store Management

Store Status

pnpm store status
pnpm store path

Show store location and status.

Prune Store

pnpm store prune

Remove unreferenced packages from store.

Linking

pnpm link <path>
pnpm link ../other-package
pnpm link --global

Link local package.

pnpm unlink <package>

Remove symlink.

Environment

Node Version

pnpm env use --global lts
pnpm env use --global 18
pnpm env list
pnpm env remove --global 16

Manage Node.js versions.

Configuration

Get Config

pnpm config get <key>
pnpm config get registry
pnpm config list

View configuration.

Set Config

pnpm config set <key> <value>
pnpm config set store-dir /path/to/store
pnpm config set registry https://registry.npmjs.org

Set configuration value.

Execution

Execute Binary

pnpm exec <command>
pnpm exec tsc
pnpx <package>
pnpm dlx <package>

Execute package binary.

Patching

Create Patch

pnpm patch <package>
pnpm patch react@18.2.0

Create patch for package.

Apply Patch

pnpm patch-commit <path>

Commit patch changes.

Audit

Check Security

pnpm audit
pnpm audit --fix
pnpm audit --json

Check for security vulnerabilities.

Other Commands

Why Package

pnpm why <package>

Show why package is installed.

Rebuild

pnpm rebuild
pnpm rebuild <package>

Rebuild native addons.

Dedupe

pnpm dedupe

Deduplicate dependencies (pnpm does this automatically).

Import

pnpm import

Generate pnpm-lock.yaml from other lockfiles.

Outdated

pnpm outdated
pnpm outdated --format list

Check for outdated packages.

Catalog (v9+)

Define Catalog

# In pnpm-workspace.yaml
catalog:
  react: ^18.0.0
  lodash: ^4.17.21

Define shared dependency versions.

Use from Catalog

# In package.json
"dependencies": {
  "react": "catalog:",
  "lodash": "catalog:default"
}

Use version from catalog.

Examples

Basic Workflow

# Initialize project
pnpm init

# Add dependencies
pnpm add react react-dom
pnpm add -D typescript @types/react

# Install all
pnpm install

# Run scripts
pnpm run dev
pnpm test
pnpm build

Monorepo Setup

# Create pnpm-workspace.yaml
echo "packages:" > pnpm-workspace.yaml
echo "  - 'packages/*'" >> pnpm-workspace.yaml

# Install all workspace dependencies
pnpm install

# Add dependency to specific package
pnpm add lodash --filter @myorg/utils

# Run command in all packages
pnpm -r run build

# Run command in specific package
pnpm --filter @myorg/app dev

Development Workflow

# Install with frozen lockfile (CI)
pnpm install --frozen-lockfile

# Update interactive
pnpm update --interactive --latest

# Check outdated
pnpm outdated

# Audit security
pnpm audit

# Why is this installed?
pnpm why lodash

# Clean install
rm -rf node_modules pnpm-lock.yaml
pnpm install

Workspace Commands

# Build all packages in order
pnpm -r run build

# Test specific package
pnpm --filter @myorg/utils test

# Add workspace dependency
pnpm add @myorg/utils --workspace --filter @myorg/app

# Run in parallel
pnpm -r --parallel run build

# Filter by pattern
pnpm --filter "./packages/ui-*" build

Store Management

# Check store location
pnpm store path

# View store status
pnpm store status

# Remove unused packages
pnpm store prune

# Add to store
pnpm store add react@18.2.0

Global Packages

# Install global package
pnpm add -g typescript

# List global packages
pnpm list -g

# Update global packages
pnpm update -g

# Remove global package
pnpm remove -g typescript

Publishing Workflow

# Bump version
pnpm version patch

# Test publish
pnpm publish --dry-run

# Publish to npm
pnpm publish --access public

# Publish with tag
pnpm publish --tag beta

# Publish all workspaces
pnpm -r publish --access public

Patch Package

# Create patch
pnpm patch react@18.2.0
# Edit files in temporary directory
# Then commit patch
pnpm patch-commit /path/to/temp/dir

# Patches are stored in patches/ directory
# and applied automatically on install

Environment Management

# Install specific Node version
pnpm env use --global 18.16.0

# Use LTS
pnpm env use --global lts

# List installed versions
pnpm env list

# Remove version
pnpm env remove --global 16

Linking Local Packages

# In package directory
pnpm link --global

# In consuming project
pnpm link --global my-package

# Or use direct path
pnpm link ../my-package

CI/CD Usage

# Install with exact versions
pnpm install --frozen-lockfile

# Fail on missing lockfile
pnpm install --frozen-lockfile --strict-peer-dependencies

# Skip optional dependencies
pnpm install --no-optional

# Production only
pnpm install --prod

Performance Optimization

# Use network concurrency
pnpm install --network-concurrency 10

# Skip scripts
pnpm install --ignore-scripts

# Prefer offline
pnpm install --prefer-offline

# Use shamefully-hoist for compatibility
pnpm install --shamefully-hoist

Troubleshooting

# Clear cache and reinstall
pnpm store prune
rm -rf node_modules
pnpm install

# Check why package is installed
pnpm why lodash

# Rebuild native modules
pnpm rebuild

# Force resolve
pnpm install --force

Notes

  • Store: Content-addressable store saves disk space
  • Hard Links: Uses hard links instead of copying
  • Strict: Stricter dependency resolution than npm
  • Fast: 2-3x faster than npm/yarn
  • Workspaces: First-class monorepo support
  • Peer Dependencies: Automatically installed
  • Lockfile: pnpm-lock.yaml for reproducibility
  • Node Modules: Nested structure with symlinks
  • Hoisting: Optional via shamefully-hoist
  • Catalog: Shared dependency versions (v9+)
  • Patches: Built-in package patching
  • Filtering: Powerful workspace filtering
  • Recursive: Run commands in all packages
  • Scripts: Lifecycle scripts like npm
  • Configuration: .npmrc and pnpm-config.json
  • Compatibility: Works with most npm packages
  • Global Packages: Stored separately from projects
  • Environment: Built-in Node.js version management
  • Publishing: Compatible with npm registry
  • Security: Automatic security audits
  • Caching: Aggressive caching for speed
  • Symlinks: May cause issues with some tools
  • Side Effects: Handled via package.json sideEffects
  • Overrides: pnpm.overrides in package.json
  • Public Hoist: Control which packages are hoisted
  • Save Prefix: Defaults to ^
  • Best Practices:
  • Use frozen-lockfile in CI
  • Keep store pruned periodically
  • Use workspaces for monorepos
  • Use catalog for version management
  • Commit pnpm-lock.yaml
  • Use filters for targeted builds
  • Consider shamefully-hoist if needed
  • Use pnpm env for Node version management

Get this worldbook via CLI

worldbook get pnpm

Comments (0)

Add a Comment

No comments yet. Be the first to comment!