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
pnpm
installed. Refer to the documentation hereRemove the
node_modules
directory from your project.Run the
pnpm import
command. This will generate apnpm-lock.yaml
from your previous package manager's lockfile. Note that you should not delete youryarn.lock
orpackage-lock.json
files until after runningpnpm import
.(Optional) To prevent accidentally using
npm
oryarn
instead ofpnpm
you 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
npm
oryarn
, such as playwright, be sure to update the commands to usepnpm
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!