Corepack is the package manager for your package manager. If you cannot decide between npm, yarn or pnpm then this might be for you.
Corepack is bundled with Node (19+). It adds metadata to your package.json file to tell CI and engineers which package manager you should be using.
Why Use Corepack?
- Team consistency: Everyone uses the same package manager version
- CI/CD reliability: Your builds use the exact same tools locally and in production
- Onboarding simplicity: New developers get the right tools automatically
Prerequisites
It is recommended, although not mandatory, (your mileage may vary) that you uninstall pnpm and yarn before proceeding.
| |
Getting Started
Enabling corepack on a project is as simple as running one command:
| |
Congratulations, you have now enabled corepack!
Doing Stuff
Big deal, right? Nothing has happened. Correct, but try this:
| |
Congrats, your project now uses the pnpm latest version try pnpm i.
If you get bored of pnpm, you can try yarn:
| |
It’s as easy as that.
How does it work?
When a teammate clones your repo and runs npm install, Corepack will:
- Detect your
packageManagerfield specifies pnpm for example - Block the command with: “This project is configured to use pnpm because package.json has a ‘packageManager’ field”
- Force them to run
pnpm installinstead - Automatically download [email protected] if they don’t have it
Things to Know
- Corepack requires Node.js 16.9+ (bundled with 19+)
- Some CI environments may need
corepack enablein their setup - You can still use
npmcommands, but Corepack will redirect to your chosen manager
Future Excerice
Why not write a Github action to install, build, test, package and publish a project but be package manager agnostic?