Do you use PNPM? If yes why?
Eagle Dev

Eagle Dev @eagledev_

About: Working ambitiously to accomplish and create great things!

Location:
India
Joined:
Dec 12, 2021

Do you use PNPM? If yes why?

Publish Date: Jun 11 '22
33 13

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!

Comments 13 total

  • Nik F P
    Nik F PJun 12, 2022

    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.

    • Eagle Dev
      Eagle DevJun 12, 2022

      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!

  • Shrihari Mohan
    Shrihari MohanJun 12, 2022

    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.

    • Nik F P
      Nik F PJun 12, 2022

      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.

  • Red Ochsenbein (he/him)
    Red Ochsenbein (he/him)Jun 12, 2022

    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)

    • Zoltan Kochan
      Zoltan KochanJun 17, 2022

      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.

  • Adam Crockett 🌀
    Adam Crockett 🌀Jun 12, 2022

    PNPN do do do doo PNPN do doo doo do 🎶

    • Eagle Dev
      Eagle DevJun 13, 2022

      That's some cool beats!

      • Adam Crockett 🌀
        Adam Crockett 🌀Jun 13, 2022

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

  • Areskul
    AreskulJun 14, 2022

    It's faaaast!!!

    • Eagle Dev
      Eagle DevJun 14, 2022

      Yup! I see it's phaaaast!!!

  • feba
    febaJun 14, 2022

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

Add comment