Pnpm

Efficient pnpm automation and integration for fast and disk-space-efficient package management

pnpm is a community skill for managing Node.js project dependencies using the pnpm package manager, covering workspace configuration, dependency installation, lockfile management, script execution, and monorepo support for efficient JavaScript project management.

What Is This?

Overview

pnpm provides tools for installing and managing npm packages using a content-addressable storage system that avoids duplicating packages across projects. It covers workspace configuration that defines monorepo structures with shared and project-specific dependencies, dependency installation that links packages from a global store instead of copying files into each node_modules directory, lockfile management that ensures deterministic installs across environments with exact version pinning, script execution that runs package scripts with filtering and parallel execution options, and monorepo support that manages cross-package dependencies within a single repository. The skill enables teams to reduce disk usage and speed up dependency installation across projects.

Who Should Use This

This skill serves frontend developers managing complex dependency trees in Node.js projects, platform teams maintaining monorepo structures with multiple packages, and organizations looking to reduce CI build times through faster dependency installation. It is also well suited for individual developers who work across several projects that share common dependencies and want to avoid redundant disk usage.

Why Use It?

Problems It Solves

npm duplicates package files across projects consuming excessive disk space when multiple projects share common dependencies. Flat node_modules structures allow packages to accidentally import undeclared dependencies creating phantom dependency issues. Monorepo dependency management with npm requires additional tooling for cross-package linking and version synchronization. Large dependency trees slow down CI pipelines when packages are downloaded and extracted fresh for each build.

Core Highlights

Content-addressable store shares package files across projects to save disk space. Strict node_modules prevents phantom dependency access through proper isolation. Workspace manager handles monorepo cross-package dependencies. Parallel installer speeds up dependency resolution and installation. These properties make pnpm particularly effective in large codebases where installation speed and correctness both matter.

How to Use It?

Basic Usage

pnpm init

pnpm add express
pnpm add -D typescript
pnpm add -D @types/express

pnpm install --frozen-lockfile

pnpm run build
pnpm run test
pnpm run dev

pnpm update
pnpm update express --latest

pnpm outdated

pnpm remove lodash

pnpm store status
pnpm store prune

Real-World Examples

packages:
  - 'packages/*'
  - 'apps/*'
  - 'tools/*'
pnpm install

pnpm -r run build

pnpm --filter @myorg/api \
  run test

pnpm --filter @myorg/web \
  add react

pnpm -r --parallel \
  run lint

pnpm --filter '...[\
  origin/main]' run build

pnpm -r list --depth 0

Advanced Tips

Use the --filter flag with glob patterns to run commands across specific workspace packages matching name or directory patterns. For example, running pnpm --filter './packages/**' run test executes tests only within the packages directory, avoiding unnecessary work in unrelated apps. Configure .npmrc with strict-peer-dependencies to catch peer dependency conflicts during installation rather than at runtime. Use pnpm deploy to create a pruned production bundle that includes only the dependencies needed for a specific package, which is useful when deploying individual services from a monorepo to reduce image size.

When to Use It?

Use Cases

Manage a monorepo with shared libraries and multiple applications that depend on common internal packages. Speed up CI pipelines by caching the pnpm store across builds to avoid redundant downloads. Enforce strict dependency isolation to prevent packages from importing undeclared dependencies.

Related Topics

pnpm, npm, yarn, package management, monorepo, workspaces, Node.js, and dependency resolution.

Important Notes

Requirements

Node.js runtime version 16 or later for full pnpm feature support. pnpm installed globally via npm or corepack for project bootstrapping. Package.json files in each workspace member for dependency declaration.

Usage Recommendations

Do: use --frozen-lockfile in CI environments to ensure builds use exact versions from the lockfile without modifications. Configure workspace protocols for internal package references to keep versions synchronized. Commit the pnpm-lock.yaml file to version control for reproducible builds across all developer machines and deployment environments.

Don't: mix package managers within a project since different lockfile formats cause dependency conflicts and inconsistencies. Delete the pnpm store directory manually since pnpm store prune handles cleanup safely. Use hoisted node_modules layout unless specific tooling compatibility requires it since this weakens dependency isolation.

Limitations

Some packages that rely on hoisted node_modules layout may not work with pnpm's strict linking without configuration adjustments. The content-addressable store requires filesystem hard link support which is unavailable on some network filesystems. Workspace protocol dependencies need conversion before publishing packages to npm registries.