pnpm vs npm: What Actually Differs
npm copies every package into each project's node_modules and hoists them flat. pnpm keeps one content-addressable store on disk, hard-links files from it, and puts only your direct dependencies at the top of node_modules. That saves disk space and stops code from importing packages it never declared. Most commands map one to one.
| Topic | npm | pnpm |
|---|---|---|
| Where package files live | A copy inside each project | One shared store, hard-linked into projects |
| node_modules layout | Flat, everything hoisted | Direct dependencies only, the rest under node_modules/.pnpm |
| Lockfile | package-lock.json | pnpm-lock.yaml |
| Workspaces declared in | workspaces field in package.json | pnpm-workspace.yaml |
| Strict CI install | npm ci | pnpm install (frozen lockfile is the default in CI) |
| Run a package without installing | npx | pnpm dlx (also pnx, pnpx) |
Updated
Both tools read the same package.json and install from the same registry, so the choice is about layout, speed of repeat installs, monorepo tooling and strictness. Below is how each one stores packages, a translator for the commands you already know, and the steps to move an existing project from npm to pnpm.
npm to pnpm command translator
| npm | pnpm |
|---|---|
npm install | pnpm install |
npm install <pkg> | pnpm add <pkg> |
npm install -D <pkg> | pnpm add -D <pkg> |
npm install -E <pkg> | pnpm add -E <pkg> |
npm install -g <pkg> | pnpm add -g <pkg> |
npm ci | pnpm install --frozen-lockfile |
npm uninstall <pkg> | pnpm remove <pkg> |
npm update | pnpm update |
npm install <pkg>@latest | pnpm update --latest <pkg> |
npm run dev | pnpm dev |
npm test | pnpm test |
npx <pkg> | pnpm dlx <pkg> |
npm exec <bin> | pnpm exec <bin> |
npm ls | pnpm list |
npm outdated | pnpm outdated |
npm audit | pnpm audit |
npm init -y | pnpm init |
npm run build -w app | pnpm --filter app build |
npm run build --workspaces | pnpm -r build |
Switch a project from npm to pnpm
Migration steps
pnpm import reads the npm lockfile so you keep the versions you already tested. Run your tests before committing.
# 1. install pnpm (standalone script from pnpm.io)
curl -fsSL https://get.pnpm.io/install.sh | sh -
# 2. convert the lockfile, then remove npm's files
pnpm import
rm -rf node_modules package-lock.json
# 3. install and test
pnpm install
pnpm testpnpm-workspace.yaml
Every folder matched here becomes a workspace package. Put the file at the repository root.
packages:
- "apps/*"
- "packages/*"Depending on a local package
workspace:* always resolves to the local copy of ui instead of a registry version.
{
"name": "web",
"dependencies": {
"ui": "workspace:*"
}
}
How each tool stores packages
npm writes a full copy of each dependency into the project's node_modules and lifts nested dependencies to the top level where it can. Ten projects that use the same library hold ten copies.
pnpm downloads each file once into a global content-addressable store. Projects get hard links to those files, so a second project with the same versions takes almost no extra space, and a new version only adds the files that changed.
Inside the project, pnpm places symlinks for your direct dependencies in node_modules and keeps everything else under node_modules/.pnpm. A package can only reach what it declared.
Workspaces and monorepos
npm workspaces are listed in the root package.json and run with -w name or --workspaces. pnpm lists them in pnpm-workspace.yaml and selects them with --filter, which also understands dependency graphs, for example a package plus everything it depends on.
pnpm's workspace: protocol pins a dependency to the local package and refuses to fall back to the registry. It is converted to a normal version range when you publish.
How it works
- Type an npm command into the translator, or click one of the examples, to see the pnpm equivalent.
- Read the storage section to understand why pnpm installs use less disk and catch undeclared imports.
- Follow the migration steps if you decide to switch, and commit the new lockfile.
Tips
- Pick one package manager per repository and delete the other lockfile, so nobody installs from a stale one.
- In CI, pnpm install refuses to touch an out of date lockfile, so commit pnpm-lock.yaml whenever package.json changes.
- If a package breaks under pnpm because it imports something it never declared, report it upstream; that import only worked by accident under npm.
- pnpm runs scripts without the word run, so pnpm dev works, as long as the script name does not clash with a built-in pnpm command.
Frequently asked questions
Is pnpm faster than npm?
pnpm often reuses files already in its store, which helps repeat installs on the same machine. Speed depends on cache state, network and project size, so time both on your own project rather than relying on a published benchmark.
Can I use pnpm with a project that has package-lock.json?
Yes. Run pnpm import to build a pnpm-lock.yaml from package-lock.json, npm-shrinkwrap.json or yarn.lock, then delete the old lockfile and node_modules and run pnpm install.
Why does my app fail to find a module after switching to pnpm?
Your code, or a dependency, imports a package that is not listed in its own package.json. npm's flat layout hid that mistake. Add the missing package as a dependency of whatever imports it.
Does pnpm need Node.js installed?
The pnpm installation docs describe pnpm 12 as a native executable that does not need Node.js to run itself. Your project scripts still need Node.js, of course.
Which one should a beginner use?
npm, because it ships with Node.js and almost every tutorial uses it. Move to pnpm when you run a monorepo, many projects on one machine, or want the stricter node_modules layout.
Related: npm commands cheat sheet, Install Node.js and npm on Mac, Vite vs Next.js, Git cheat sheet.
Start a 7-day free trial or see all free tools. On We.Inc you get a 7-day free trial, not a free plan: card needed, $0 today, cancel before it ends and you pay nothing. AI building is on paid plans from $20 a month.
More in Guides
- Website Portfolio Examples: Photographers, Designers and Architects | How-to Guide
- Respecting prefers-reduced-motion
- How to Build a Print-on-Demand Website
- Ecommerce Product Page Design: Anatomy and Examples
- How to Turn Your Website into a Progressive Web App
- Public Library Website Accessibility: Catalogs, Event Calendars and the Vendors Behind Them | How-to Guide
- Rate Limiting: How It Works, With a Live Simulator
- React Chart Libraries Compared: One Chart, Six Libraries
Product
Who It's For
- For Agencies
- For Freelancers
- For Hosting Providers
- For SaaS Platforms
- For Startups
- For Financial Services
- For Healthcare
Features
Resources
- Blog
- Help Center
- Free Business Tools
- Free UI Components
- Website Templates
- Template Collections
- Website Examples
- Guides
- Comparisons
- Alternatives
- Best Lists
- Reviews
- Pricing Guides
- Use Cases
- Glossary & Guides
- Integrations
- Developers
- Benchmark
- Windows App