DEV Community

Ayu Adiati
Ayu Adiati

Posted on

Which Package Managers?

Hi Friends 👋🏼,

Out of my curiosity, what are the differences between npm, yarn and pnpm? Which one do you use and why?

A while ago, many said that yarn runs faster than npm. But then, that's no longer the case. They both are the same -- in my opinion as a Windows user. But I'm not familiar yet with pnpm.

Top comments (10)

Collapse
 
ben profile image
Ben Halpern

I'd say...

  • npm is best for simplicity — i.e. working along, don't overthink it mode.
  • yarn is best for consistency, i.e. lock that ensures everyone has the same dependency structure
  • pnpm is best for performance and resources, another possible thing to optimize for when things get big and complicated.

Not my area of expertise, but that's my high level idea.

Collapse
 
adiatiayu profile image
Ayu Adiati

Thanks for the insights, Ben! 🙏😄

Collapse
 
knopkem profile image
Michael Knopke

NPM also has a lockfile, but it's not enforced without using "npm ci" command.

Collapse
 
tbroyer profile image
Thomas Broyer

And yarn will happily update the lockfile (like npm install) without --frozen-lockfile.

Collapse
 
diomed profile image
May Kittens Devour Your Soul

from what I've been told it's best to use pnpm, but you cant have it independently from npm, I think. basically, while npm installs every single dependency ever and makes your project bundle from like 1.5 or 2mb to 100 or 200 mb , pnpm will do the same. but the trick with pnpm is that it will do it just once, and not for multiple projects.

so yeah... what I've learned is - package managers are hell.
but one cant do without them.

Collapse
 
adaptive-shield-matrix profile image
Adaptive Shield Matrix

pnpm is best

but as a windows user you may not notice the performance improvements (because windows ntfs throttles / scans for viruses all created and compiled source files - every time they are touched and/or read - and even if you disable/exclude the dir in your av)

in Linux/Mac the performance of pnpm is like

  • 10x faster vs npm
  • 2x faster vs yarn

As a single dev on windows you may not care (for now), but you will - the moment you want to run it in any kind of cloud env or CI

Collapse
 
adiatiayu profile image
Ayu Adiati

Thank you! It's answering why I, as a Windows user, don't see major differences between them 😄

Collapse
 
prahladyeri profile image
Prahlad Yeri

I use npm for its simplicity and popularity but yarn is good too.

JS is just one language in the backend toolchain, folks often need to work with other package managers too like PHP's composer for backend scripting and Python's PIP for data science libraries. Eventually, all these package managers could be clubbed into one "global" package manager with single backend. Github is in the right position to do this and I think they're making some efforts along these lines.

Collapse
 
michaldziuba03 profile image
Michał Dziuba

In most cases I use pnpm because I see performance gains on my machine and many projects where I am involved use pnpm anyway.

Sometimes I use npm when project is really simple or I want to demonstrate something in guides/docs - npm is just always installed with Node.js so anyone who reads guide can easily follow steps.

Collapse
 
endymion1818 profile image
Ben Read

Yep this is a good approach 👍 things are always changing in the JavaScript ecosystem!