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:
- Make sure you have
pnpminstalled. Refer to the documentation here - Remove the
node_modulesdirectory from your project. - Run the
pnpm importcommand. This will generate apnpm-lock.yamlfrom your previous package manager’s lockfile. Note that you should not delete youryarn.lockorpackage-lock.jsonfiles until after runningpnpm import. - (Optional) To prevent accidentally using
npmoryarninstead ofpnpmyou can set up your project to only allowpnpm. 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
- (Optional) If you have other tools that rely on
npmoryarn, such as playwright, be sure to update the commands to usepnpminstead.
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!