Tooling

Why I use PNPM over YARN and NPM — and you should too

Feb 10, 2023Updated Nov 24, 20264 min readRami Mustaklem

Updated November 2026: added a note on pnpm’s latest benchmarks.

Introduction

These days if anyone wants to work or start a JavaScript project, they will probably start by running the npm init command or cloning a repository that will have a package.json file which consists of the configurations and dependencies for the project. A JS project needs packages (dependencies), wether on the client side or the server side, in order to build up an application consisting of a lot of functionalities, like authentication, routing, connect it to DB, encrypting and others, or to use a framework like ExpressJS on the server or Angular on the client, and to avoid reinventing the wheel and building everything from scratch. For that we have package managers like NPM, Yarn, and PNPM, that are built for the Node.js JavaScript runtime environment, and in this article I am comparing these 3 package managers and presenting the why, to use PNPM over others.

NPM

If you’re a JS developer, you know NPM, it’s the default package manager that comes with the Node.js runtime environment. It reads and updates your package.json file, or adds/removes dependencies using the npm install command, installs inside a node_modules folder, and tracks each package version installed with the package-lock.json file, to keep track of the versions installed, so whenever you clone and install the project on other devices you will be able to replicate and install the same project dependencies even across operating systems. NPM though, is not the best among package managers due to a few issues.

One of the problems with NPM is the inconsistency of the same package version installed for the same project on different devices. Running npm install follows the package-lock.json file only as long as it matches the package.json file, and when they don’t match, it updates the lock file instead, which can lead to inconsistent installations and lock files between devices. The npm ci command solves this by installing exactly what’s in the lock file, and failing if it doesn’t match the package.json, which is why it should be used in CI and production builds. Tracking the lock file with version control is also important for that same goal, to ensure a team of developers share the same project installation across. Another issue is the duplication of the same package across different projects, since each project gets its own copy, and the “flat” node_modules folder structure, which leads to modules having access to packages they do not depend upon, also known as phantom dependencies.

YARN

Yarn is also a Node.js package manager that was developed by Facebook back in 2016. It was created as a collaboration of Facebook, Exponent, Google, and Tilde, mainly to solve the issues NPM was having, consistency, security and performance with large code bases. Yarn uses a yarn.lock file to track package versions and checksum verifications. One of the main issues that Yarn fixes, is the package inconsistency, and as per their website Yarn guarantees that an install that works now will continue to work the same way in the future. Performance-wise, it is not in all cases faster than NPM, and for slow or unstable connections, it is very slow. From a security perspective, Yarn ensures the integrity of packages installed before their code is executed. Yarn 2+ (known as Yarn Berry), released in 2020, also introduced Plug’n’Play (PnP), which drops the node_modules folder altogether and solves the same phantom dependencies issue, but some tools and packages still need extra configuration to work with it.

PNPM

Fast, disk space efficient package manager.

Stands for “Performant NPM”, which was made specifically to save disk space and boost installation speeds.

PNPM is up to 2x faster than the alternatives.

PNPM performance stats vs yarn and npm

PNPM performance stats vs yarn and npm

Update (November 2026): pnpm’s benchmarks have changed a lot since I wrote this. The current benchmarks page only compares pnpm with npm, and shows pnpm being several times faster in every scenario, and a lot more with a warm cache. Keep in mind these are pnpm’s own numbers measured on their own setup, so your results may vary.

Explaining on their website as to why PNPM is this fast, to answer the question, it’s because PNPM does not have blocking stages of installation. Each dependency has its own stages and the next stage starts as soon as possible. To explain, each package has 3 stages, resolving, fetching and writing. Basically each package installation does not block other packages, as soon as a package is fetched over the wire, the installation starts, and doesn’t wait for previous packages to finish before starting.

When you use PNPM to install packages from your package.json file, what PNPM does is that it caches all those node_modules to a single content storage on your disk and shares these packages between projects. If 2 projects share the same package version, then these 2 projects use the same installed package on disk, and it is hard linked from that store to the node_modules directory of your project without the need to duplicate and copy all packages to each project.

PNPM reusing a lot of already installed packages

A snippet of PNPM reusing a lot of already installed packages

PNPM has a non-flat node_modules structure by default, which also means that if a project installs package A, package A installs package B in order to function, package B is symlinked inside package A’s own node_modules, so package A can access it, but your project can’t import package B directly unless it’s declared in your package.json.

There’s a list of big companies using PNPM, including Microsoft, Prisma, Wix and others. PNPM uses a pnpm-lock.yaml file to track package versions and checksum verifications, and like npx to npm, pnpm also has pnpm dlx to run packages without adding them to your project.

Conclusion

Ever since I started using PNPM, I felt the difference in performance, especially on a slow connection. If you want to use a more disk efficient, performant and reliable package manager, go for PNPM. You can check out their website for more data and info.


Using React useState to control form inputs? Learn here on why it’s not the best practice.

R
Rami Mustaklem
Senior Full Stack Developer