pnpm Introduction - Fast Package Manager

beginner | 30 min read | 2025.12.15

What You’ll Learn in This Tutorial

✓ pnpm installation
✓ Basic commands
✓ Workspace setup
✓ Migration from npm

Step 1: Installation

# npm
npm install -g pnpm

# Homebrew
brew install pnpm

# corepack (Node.js 16.13+)
corepack enable
corepack prepare pnpm@latest --activate

Step 2: Basic Commands

# Install packages
pnpm install

# Add dependencies
pnpm add express
pnpm add -D typescript

# Remove
pnpm remove express

# Run scripts
pnpm run dev
pnpm dev  # run is optional

# Update
pnpm update
pnpm update --latest

Step 3: Workspace Setup

# pnpm-workspace.yaml
packages:
  - 'apps/*'
  - 'packages/*'
// package.json
{
  "name": "my-monorepo",
  "private": true,
  "scripts": {
    "dev": "pnpm -r dev",
    "build": "pnpm -r build"
  }
}

Step 4: Workspace Operations

# Install to specific package
pnpm add lodash --filter web

# Reference internal packages
pnpm add @repo/ui --filter web --workspace

# Run in all packages
pnpm -r run build

# Parallel execution
pnpm -r --parallel run dev

Step 5: package.json Dependencies

// apps/web/package.json
{
  "dependencies": {
    "@repo/ui": "workspace:*",
    "@repo/utils": "workspace:^1.0.0"
  }
}

Step 6: Migration from npm

# Delete node_modules
rm -rf node_modules

# Delete package-lock.json
rm package-lock.json

# Install with pnpm
pnpm import  # Convert from package-lock.json
pnpm install

Step 7: Configuration File

# .npmrc
shamefully-hoist=true
strict-peer-dependencies=false
auto-install-peers=true

Best Practices

✓ Manage with corepack
✓ Commit pnpm-lock.yaml
✓ Project settings in .npmrc
✓ workspace:* for internal references

Summary

pnpm is a disk-efficient and fast package manager. The workspace feature makes monorepo management easy.

← Back to list