DEV Community

Cover image for Do you use PNPM? If yes why?

Do you use PNPM? If yes why?

Eagle Dev on June 11, 2022

PNPM is said to be most efficient package manager. I'm also thinking to switch from slower npm to faster PNPM.

Before switching I would like to know about pros and cons of PNPM.

Let me know in comments!

Collapse
 
nikfp profile image
Nik F P

After using npm, Yarn, and pnpm, I am happy to stick with pnpm. Here's what I like about it.

  • It's faster. This is due to how it stores dependencies. Say you install React at version 18 in a project. Pnpm will first download that version of React to its own global cache, and then in your node_modules it will create a link to the global React installation. Then, if React also needs something, like lodash for example, it does the same thing for lodash. Now if another React dependency also needs lodash, it will reuse the downloaded version in its cache instead of downloading again. So initial installs go faster.
  • Next, say you need to delete your node_modules and reinstall. Pnpm will reuse all the dependencies in its cache again if possible, so the reinstall is REALLY fast.
  • The same cache works between projects as well. So a brand new project on a machine that already has a lot of dependencies in the cache is likely to install very fast yet again.
  • Workspaces just plain works, and I had a lot of pain points in both npm and yarn trying to use workspaces.
  • Since each dependency and version number is only downloaded once and then linked in to each project, you get a huge savings in disk space as nothing is duplicated. This is great for a dev machine, but I've also seen savings lately in the size of docker containers when building them with pnpm vs npm
  • pnpm is more strict with dependencies, meaning you have to be more intentional and explicit when declaring them. The result is what your project needs will be in the package.json, or your project doesn't run.

I keep pnpm as the only globally installed package on my dev environment, and everything is listed in each project. This doesn't cause disk space bloat because of how pnpm works. I've been very happy with the switch, and will only use npm or yarn if I have to. To be honest I haven't come across any cons that I can think of, other than I wish more people would adopt it.

Pick a little side project and give it a shot. After the initial adjustment to the syntax changes with commands I think you will be impressed.

Collapse
 
eagledev_ profile image
Eagle Dev

Thanks for your response! I'll definitely use PNPM on a side project first and after reading your response I'm sure speed of PNPM will impress me!

Collapse
 
shrihari profile image
Shrihari Mohan • Edited

Hey just a doubt regarding PNPM ?

We at our company uses NPM on Angular ( Pretty Big Project ). That takes like 30 MINUTES for production build.

Is it possible to reduce build time when using PNPM , just wondereing.

Collapse
 
nikfp profile image
Nik F P

It should help speed your builds up, but it's not going to be a magic bullet. It will help with downloading and resolving dependencies, but any compiling, code transforms, test runs, etc. probably won't change much, if at all. So your gains won't be drastic with pnpm alone.

It sounds like what you need is a tool like Nx or Turborepo. Both tools allow you to define builds in steps and cache steps as you go, and I'm pretty sure both allow for cached steps to be shared between dev and ci environments also. (I know turborepo does) These tools are designed for monorepo's though so if you have a monolith going, you might need to tease some modules into separate packages to see a real benefit. I've been hearing a LOT about both on the podcast circuit but haven't tried either on my own yet.

Collapse
 
shrihari profile image
Shrihari Mohan • Edited

Hey Nik , thanks !

Collapse
 
syeo66 profile image
Red Ochsenbein (he/him)

Tried it on several of my private projects. Unfortunately it worked only in 25% of all cases. Seems a hassle to get it to work in the other ones... so, I'll stick to yarn. Maybe the story would be different when starting new projects (which I'll certainly try to start with pnpm)

Collapse
 
zkochan profile image
Zoltan Kochan

When pnpm doesn't work, you can always set the node-linker=hoisted setting and pnpm will create a regular hoisted node_modules without using symlinks. It will work with all projects that work with Yarn.

Collapse
 
areskul profile image
Areskul

It's faaaast!!!

Collapse
 
eagledev_ profile image
Eagle Dev

Yup! I see it's phaaaast!!!

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

PNPN do do do doo PNPN do doo doo do 🎶

Collapse
 
eagledev_ profile image
Eagle Dev

That's some cool beats!

Collapse
 
adam_cyclones profile image
Adam Crockett 🌀

You know it! Although I may be to old for some to get the reference

Collapse
 
feba33 profile image
feba

It's pretty good but some older packages won't work. It may be placebo but I feel it works faster too.