Switch from yarn / npm to pnpm

Why pnpm

If you're looking for a faster alternative to package managers like npm and yarn, consider using pnpm. Not only is pnpm more performant when it comes to fetching, resolving, and storing dependencies, but it also offers an easy migration process.

Migration Steps

To get started with pnpm, follow these steps:

  1. Make sure you have pnpm installed. Refer to the documentation here

  2. Remove the node_modules directory from your project.

  3. Run the pnpm import command. This will generate a pnpm-lock.yaml from your previous package manager's lockfile. Note that you should not delete your yarn.lock or package-lock.json files until after running pnpm import.

  4. (Optional) To prevent accidentally using npm or yarn instead of pnpm you can set up your project to only allow pnpm. Here are two options:

a. In your package.json file, add the following script: https://www.npmjs.com/package/only-allow

Summary - in your package.json:

"scripts": {
    "preinstall": "npx only-allow npm"
  }

b. Add the following to your package.json file:

"engines": {
  "npm": "Please use pnpm",
  "yarn": "Please use pnpm",
}

Then, create a .npmrc file and add the following line:

engine-strict=true
  1. (Optional) If you have other tools that rely on npm or yarn, such as playwright, be sure to update the commands to use pnpm instead.

And that's it! With just a few simple steps, you can start using pnpm and take advantage of its faster performance.

I hope this helps you make the switch to pnpm. If you have any questions or feedback, feel free to reach out from the socials below. Thanks for reading!