npm vs. yarn vs. pnpm

npm vs. yarn vs. pnpm
Photo by Pankaj Patel / Unsplash

If you've ever worked with JavaScript you'll probably know that there are 2 major package managers, npm which comes with node.js and yarn which is developed by Facebook but there is a third one called pnpm which might have better answers to npm's problems than yarn.


npm has been the defacto package manager for millions of JavaScript developers until yarn showed up. At the time npm had a lot of issues like unrealiable installations, no lockfile at all or at best an unrealiable one and slow installation times. All of those things were annoyances for small developers but for large enterprises like Facebook those things were real productivity blockers, that's where yarn enters the stage.


yarn has taken the hearts of millions of developers by storm since the release of it a few years ago. It installed packages magnitudes faster than npm could, had a lockfile that guaranteed consistency across machines and all kinds of nifty mechanisms to avoid corruption or downloading broken packages. It also brought the concept of workspaces to developers which made working with mono-repos less of a pain.

But yarn itself isn't without issues, it's not uncommon to need to clear the cache every now and then because some integrity checks start to fail or having to reinstall it altogether when installed through some package manager like brew. Those are minor nuances but can become annoying as they keep repeating.


pnpm is the newest package manager in the JavaScript Ecosystem and tries to combine the best of npm and yarn and continue to improve on them. It takes quite a different approach to installing packages by using symlinks to avoid duplicate installations.

If you pull in 10 dependencies via npm or yarn and all of them rely on the same lodash version you will end up with 10 copies of lodash in your node_modules folder. With pnpm you will end up with a single copy of lodash because the symlink of the first installation will let pnpm know that the lodash version that is needed has already been installed.


These days npm and yarn have pretty much the same performance and consistency with their lockfiles which means there is no real reason to use yarn unless you rely on the workspace feature. yarn 2 is currently under development which will bring a lot of improvements which should put it once again ahead of npm so make sure to check that out.

If you aren't required by your work to use npm or yarn I would recommend to give pnpm a shot and see how it works out for you. It'll definitly save you some time and disk space.