Back to all articles
TechnicalFeature

Why pnpm Is Better Than npm and Yarn

pnpm is faster, uses less disk space, and prevents dependency bugs. Here's why Vibestacks uses it and why you should too.

Why pnpm Is Better Than npm and Yarn

If you've cloned Vibestacks, you've noticed we use pnpm instead of npm or Yarn. This isn't just personal preference - pnpm solves real problems that the other package managers don't.

Let me explain why we made this choice.

The Problem With npm and Yarn

When you run npm install, here's what happens:

  1. npm downloads every package your project needs
  2. It copies those packages into your node_modules folder
  3. If you have 10 projects using React, you have 10 copies of React on your disk

This creates two problems:

Wasted disk space. A typical Next.js project has 200-400MB of node_modules. Ten projects? That's 4GB of duplicate packages sitting on your drive.

Slow installs. Every npm install downloads and copies files, even if you installed the same packages yesterday in a different project.

Yarn improved some things (faster installs, better lockfiles) but still copies packages into each project.

How pnpm Is Different

pnpm takes a fundamentally different approach: content-addressable storage.

Instead of copying packages into each project, pnpm:

  1. Stores all packages in a single global location (~/.pnpm-store)
  2. Creates hard links from your project's node_modules to that store

If you have 10 projects using React 18.2.0, there's only one copy of React on your disk. Each project links to that same copy.

~/.pnpm-store/
  └── react@18.2.0/
      └── (single copy of React)

project-1/node_modules/react → links to store
project-2/node_modules/react → links to store
project-3/node_modules/react → links to store

The result? Massive savings in disk space and installation time.

The Numbers

Here's a real comparison on a Next.js project with ~150 dependencies:

MetricnpmYarnpnpm
Install time (cold)45s38s22s
Install time (cached)12s9s3s
node_modules size387MB385MB287MB
Disk usage (10 projects)3.8GB3.8GB~400MB

pnpm is roughly 2x faster on cold installs and uses ~90% less disk space across multiple projects.

Strict Dependencies (The Hidden Benefit)

This is the feature that saves you from subtle bugs.

With npm and Yarn, you can accidentally import packages you didn't explicitly install. Here's how:

// Your package.json
{
  "dependencies": {
    "some-library": "^1.0.0"
  }
}
// some-library's package.json (you don't control this)
{
  "dependencies": {
    "lodash": "^4.0.0"
  }
}
// Your code
import { debounce } from 'lodash'; // This works! But shouldn't.

npm installs lodash (because some-library needs it) and hoists it to your node_modules root. Your code can import it even though you never added it to your package.json.

This is called phantom dependencies. It works until:

  1. some-library updates and removes lodash
  2. You deploy to a different environment with different hoisting
  3. A teammate has a slightly different lockfile

Then your build fails mysteriously.

pnpm prevents this entirely. Each package only has access to its declared dependencies. If you try to import lodash without adding it to your package.json, you get an error immediately - not in production three months later.

Why Vibestacks Uses pnpm

We chose pnpm for three reasons:

1. Faster Development

When you're iterating quickly, waiting 45 seconds for npm install kills momentum. pnpm's 3-second cached installs keep you in flow.

2. Cleaner Dependencies

The strict dependency resolution catches bugs early. If you import something, it must be in your package.json. No phantom dependencies, no "works on my machine" surprises.

3. Better for Monorepos

If you grow Vibestacks into a monorepo (shared packages, multiple apps), pnpm's workspace support is best-in-class. The shared store means packages aren't duplicated across workspace members.

Common pnpm Commands

If you're coming from npm, most commands are identical:

# Install dependencies
pnpm install

# Add a package
pnpm add react-query

# Add a dev dependency
pnpm add -D typescript

# Remove a package
pnpm remove lodash

# Run a script
pnpm run dev
# or just
pnpm dev

# Update packages
pnpm update

# Clear the store (rarely needed)
pnpm store prune

The only real difference is typing pnpm instead of npm.

Installing pnpm

If you don't have pnpm installed:

# Using npm (ironic, but works)
npm install -g pnpm

# Using Homebrew (Mac)
brew install pnpm

# Using Corepack (built into Node 16+)
corepack enable
corepack prepare pnpm@latest --activate

We recommend the Corepack approach since it automatically manages the pnpm version per project.

What About Yarn?

Yarn was a significant improvement over npm when it launched in 2016. It introduced lockfiles, parallel installs, and better caching.

But pnpm has caught up and surpassed it:

FeatureYarn ClassicYarn Berry (v2+)pnpm
SpeedFastFastFastest
Disk efficiencyPoorGood (PnP)Best
Strict dependenciesNoYes (PnP)Yes
Monorepo supportGoodGoodBest
Learning curveLowHigh (PnP)Low
Ecosystem compatibilityGreatSome issuesGreat

Yarn Berry's Plug'n'Play (PnP) mode achieves similar benefits to pnpm but requires significant changes to your workflow and has compatibility issues with some tools.

pnpm gives you the benefits without the breaking changes.

The One Downside

pnpm's strict dependency resolution can occasionally cause issues with poorly-written packages that rely on phantom dependencies.

If you hit this, you have two options:

  1. Add the missing dependency explicitly (the correct fix)
  2. Use pnpm.packageExtensions in package.json (workaround for broken packages)

In practice, this is rare with well-maintained packages. And when it happens, it's exposing a bug that would have bitten you eventually anyway.

Conclusion

pnpm is faster, uses less disk space, and prevents dependency bugs. There's no real downside for new projects.

That's why every Vibestacks project uses pnpm by default. When you clone the repo and run pnpm install, you're getting the fastest, most reliable package manager available.


Already using npm or Yarn? Switching is easy:

# Remove old lockfile and node_modules
rm -rf node_modules package-lock.json yarn.lock

# Install with pnpm
pnpm install

That's it. Your project now uses pnpm.

Questions? Join our Discord community.