I’m a little late to the pnpm party. Okay, a lot late. But hey, I finally made the leap! Here why i moved from npm and you should if you haven't already (no judgment 😜).
But first, What is a Package Manager?
Package manager helps you:
- Download and install packages (dependencies).
- Resolve and manage versions.
- Link dependencies efficiently.
- Run scripts and tools defined in your project (via
package.json).
How dependencies are stored?
| Feature | npm | pnpm |
|---|---|---|
| Storage Model | Flat node_modules structure | Hard links from a global store |
| Disk Usage | Duplicates packages per project | Shares packages globally across projects |
| Speed | Slower for large deps | Much faster (due to caching + linking) |
| Determinism | Improved with npm v9+ | Highly deterministic out of the box |
| Installation Time | Slower | Faster (parallel + efficient linking) |
Switching from npm to pnpm in an Existing Project
- Install
pnpmglobally:
npm install -g pnpm
- Remove
node_modulesandlockfilefrom your existing repositoiry:
rm -rf node_modules package-lock.json
- Install dependencies using
pnpm:
pnpm install
- update your
enginesfield inpackage.json:
"engines": {
"node": ">=22.20.0",
"pnpm": ">=10.18.0"
}
Why Use pnpm Over npm?
pnpminstalls every unique version of a package once globally, then hard-links it into your project.- So if 10 projects use
react@18.2.0, it's stored once, used many times.