pnpm vs npm: Speed, Workspaces & Switching Guide
pnpm uses a shared content-addressable store and a linked dependency layout; npm uses its own cache and dependency installation layout. Both support workspaces and reproducible CI installs. Choose pnpm for its workspace and dependency-management workflow, or keep npm when the current project works well. Import the existing lockfile before evaluating a switch.
Last updated: 2026-09-09
pnpm vs npm: which is better?
Use pnpm when its workspace tools and dependency layout solve a real project problem. Staying on npm is reasonable when installs, CI and maintenance already work. Verify a migration on a branch before replacing the active lockfile.
- →Choose pnpm if Explicit workspace dependencies and shared package storage
- →Choose npm if An established npm workflow with no pressing migration need
In This Comparison
Side-by-Side Comparison
| Category | pnpm | npm |
|---|---|---|
| Install evidence | Benchmark your own cold and cached installs | Benchmark the same project and cache states |
| Disk model | Shared content-addressable package store | npm cache with project node_modules |
| Workspaces | pnpm-workspace.yaml and workspace: dependencies | package.json workspaces and workspace flags |
| CI install | pnpm install --frozen-lockfile | npm ci |
| Migration input | pnpm import from package-lock.json | Keep the committed npm lockfile |
| Compatibility | Check undeclared dependencies and build scripts | Check package scripts and Node version |
pnpm
- Install evidence
- Benchmark your own cold and cached installs
- Disk model
- Shared content-addressable package store
- Workspaces
- pnpm-workspace.yaml and workspace: dependencies
- CI install
- pnpm install --frozen-lockfile
- Migration input
- pnpm import from package-lock.json
- Compatibility
- Check undeclared dependencies and build scripts
npm
- Install evidence
- Benchmark the same project and cache states
- Disk model
- npm cache with project node_modules
- Workspaces
- package.json workspaces and workspace flags
- CI install
- npm ci
- Migration input
- Keep the committed npm lockfile
- Compatibility
- Check package scripts and Node version
Winner by Category
Best for existing npm projects
npmA project already using npm needs no package-manager migration.
Best for workspace dependency control
pnpmFiltering and workspace protocols make multi-package tasks explicit.
Best for finding undeclared imports
pnpmIts dependency layout makes undeclared imports easier to identify.
Should you choose pnpm or npm?
Use pnpm when its workspace tools and dependency layout solve a real project problem. Staying on npm is reasonable when installs, CI and maintenance already work. Verify a migration on a branch before replacing the active lockfile.
When should you use each tool?
Choose pnpm
Explicit workspace dependencies and shared package storage
Choose npm
An established npm workflow with no pressing migration need
The practical difference between pnpm and npm
Both install packages from the npm ecosystem and run package scripts. The important differences appear in dependency layout, workspace configuration and version-specific install policies. Neither changing the command name nor adopting a popular tool guarantees a faster build.
Start with a reason to switch: repeated installation overhead, a growing workspace, or difficulty tracking package ownership. For a stable single application, migration has a review cost and may add little value.
Install speed: compare equivalent cold and cached runs
This guide does not publish a 13Labs installation benchmark. The pnpm project publishes its own benchmark methodology and results; these are vendor-maintained examples rather than a universal multiplier. Real results depend on dependency versions, network access, cache state, lifecycle scripts and filesystem behaviour.
To evaluate your project, use isolated copies of the same commit and the same Node version. Record both package-manager versions and equivalent dependency resolutions. Measure clean installs with empty caches separately from clean installs with restored caches. Repeat each case, include cache restore time in CI, and report median and range. Run the build and tests after installation so a skipped native build is not mistaken for an improvement.
Sources
What changes inside node_modules?
pnpm stores package content centrally and links it into projects. Its usual isolated layout exposes declared direct dependencies at the project level. If your code imports a package merely because another dependency installed it, switching can reveal that missing declaration. Add the package to the correct manifest rather than immediately enabling broad hoisting.
For example, if your application imports lodash but package.json only declares a library that itself depends on lodash, declare lodash directly. Do not treat dependency isolation as protection against a compromised package: installed dependencies and approved scripts still need review.
Disk comparisons need care because hard links and shared content can be counted differently by filesystem tools. Report the shared store and all project directories consistently instead of promising a fixed percentage saving.
Workspace setup and commands side by side
Assume packages/app has the package name @example/app and packages/ui has @example/ui. npm workspaces are declared in the root package.json. For pnpm, add pnpm-workspace.yaml before importing a workspace lockfile. Keep the real package names in filters. The workspace: protocol explicitly requires a local pnpm workspace dependency.
{
"private": true,
"workspaces": ["packages/*"]
}# pnpm-workspace.yaml
packages:
- 'packages/*'| Task | npm | pnpm |
|---|---|---|
| Add a registry dependency to app | npm install lodash --workspace=@example/app | pnpm --filter @example/app add lodash |
| Run app tests | npm run test --workspace=@example/app | pnpm --filter @example/app run test |
| Run existing workspace build scripts | npm run build --workspaces --if-present | pnpm -r --if-present run build |
# pnpm: make app depend explicitly on the local UI package
pnpm --filter @example/app add '@example/ui@workspace:*'Migrate by importing the existing npm lockfile
Start on a clean branch or disposable checkout. Record the Node version supported by your project and select a compatible, exact pnpm version. Install pnpm using the official instructions for that Node version; do not assume Corepack is bundled with every Node release. Corepack was bundled from Node 14.19 up to, but not including, Node 25.
Keep package-lock.json in place for pnpm import. For a monorepo, create pnpm-workspace.yaml first. Importing gives you a starting dependency resolution, not a guarantee of an identical graph: inspect the generated lockfile and peer dependencies. The commands below assume pnpm is installed and the project has test and build scripts.
git switch -c evaluate-pnpm
node --version
npm --version
pnpm --version
# Retain package-lock.json: it is the import input.
pnpm import
pnpm install --frozen-lockfile
pnpm run test
pnpm run build
git diff -- package.json package-lock.json pnpm-lock.yaml pnpm-workspace.yaml- Review missing dependency declarations, peer warnings and native module builds.
- Update scripts, Dockerfiles, deployment settings and CI to use the selected manager.
- Record the exact pnpm version in the packageManager field using the official setup workflow.
- Keep the old lockfile until validation passes; remove the superseded file only when the team adopts pnpm.
- Re-run installation and checks in a fresh checkout before merging.
CI installs and dependency build-script review
For npm CI, commit package-lock.json and use npm ci. For pnpm CI, commit pnpm-lock.yaml and use pnpm install --frozen-lockfile. Both workflows should fail on an incompatible manifest/lockfile combination rather than silently updating dependency resolution. Configure the same Node and package-manager versions locally and in CI.
The pnpm CI example assumes the runner has installed the project’s pinned pnpm version. Cache keys should include the operating system, Node version and lockfile; measure cache restoration cost before assuming caching is faster. Build-script approval is a separate step: review dependencies that need native builds, approve only those needed using the commands supported by your pnpm version, and commit the generated policy. Do not automatically approve everything in CI.
# npm runner with the project Node/npm versions installed
npm ci
npm run test
npm run build# pnpm runner with the pinned package-manager version installed
pnpm install --frozen-lockfile
pnpm run test
pnpm run build# Local review, for pnpm versions supporting this command
pnpm approve-buildsWhen to switch and when to stay
Choose pnpm when its explicit workspace dependencies, filtering and shared store help your team. Stay with npm when the existing project and deployment pipeline are reliable and there is no measured or operational reason to change. Avoid switching package managers during an unrelated production incident.
Before deciding, compare successful builds, dependency changes and maintenance effort as well as installation time. For application deployment decisions after installation, see Railway vs Vercel and Railway vs Render.
Frequently Asked Questions
Is pnpm always faster than npm?
No universal multiplier applies. Compare the same project and versions with cold and cached installs, include lifecycle scripts and cache restoration, and verify successful builds. This guide does not claim a 13Labs benchmark.
Should I delete package-lock.json before switching to pnpm?
No. Keep it for pnpm import, which generates a pnpm lockfile from the existing resolution. Review and validate the result before removing the superseded npm lockfile.
Does npm support monorepos?
Yes. npm workspaces support installing dependencies and running scripts in selected packages. pnpm uses pnpm-workspace.yaml and offers filtering and the workspace: dependency protocol.
Is Corepack included in all recent Node versions?
No. Corepack was bundled from Node 14.19 up to, but not including, Node 25. Follow the current pnpm installation instructions for the Node version your project supports.
Does pnpm make dependencies safe?
No package manager guarantees that dependencies are safe. pnpm dependency isolation and build-script approval are useful controls, but you still need to review packages, updates and the scripts you permit.
Done comparing? Pick your path.
Comparing tools is half the battle. Shipping with one is the other half.