DEV Community

Discussion on: Do you use PNPM? If yes why?

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!