Matt PocockMatt is a well-regarded TypeScript expert known for his ability to demystify complex TypeScript concepts.
I've just learned about corepack, a tool that bundles with Node.js and solves a bunch of problems with handling package managers. But I'll be using it in my development setup from now on.
corepack makes sure you're using the correct package manager for your project. To configure the package manager for your project, add the packageManager field to your package.json:
You must specify an exact version of the package manager you want to use - not a range. All of the below are not valid:
{ // not valid: uses a range "packageManager": "npm@^10.8.1", // not valid: specifies 'latest' "packageManager": "pnpm@latest", // not valid: must specify an exact version "packageManager": "yarn"}
corepack intercepts calls to pnpm and yarn to make sure you're using them correctly. This is set up by running corepack enable.
Without running corepack enable npm, you won't get the same validation when using npm. So, we run corepack enable npm to make sure that npm gets treated the same way as pnpm and yarn.