DEV_TOOLBOX

Corepack

Corepack is a zero-runtime-dependency Node.js script that acts as a bridge between Node.js projects and the package managers they are intended to be used with during development.

Usage & Commands

As of September 2024, Corepack is still bundled with Node so we don't need to install it. But there are plans to make it an independent package.

corepack enable

Enable Corepack

corepack enable

After enabling Corepack, and then running a command with a specific package manager, you will see a new packageManager field in your package.json file. If if doesn't have one. The added packageManager field has a dirty look value but can be manually cleaned. to make it look like this:

package.json
{
  "name": "project",
  "version": "0.0.0",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "express": "^4.18.2"
  },
  "packageManager": "pnpm@9.10.0"
}

If it already has a packageManager field and you tried to use a different package manager, the command will fail with an error message saying that the package manager you should use is the one that's in the packageManager field.

corepack disable

Disable Corepack

corepack disable

NOTE

Sometimes we may need to use a different runtime such as bun. This is the time we need to disable Corepack.