gitmyhub

corepack

TypeScript ★ 3.7k updated 2d ago

Package manager version manager for Node.js projects

Corepack is a small tool that ships with Node.js (the platform that runs JavaScript outside a browser) and solves a common headache: different projects often need different versions of package managers like Yarn or pnpm, and keeping those versions consistent across a team is error-prone. Corepack acts as a middleman so that when you run a command like "yarn install" inside a project, it makes sure the right version of Yarn is used, downloading it if necessary, without you having to install anything yourself.

The way it works is straightforward. A project author adds a single line to their project's configuration file declaring which package manager and version the project expects. When anyone else on the team runs a package manager command inside that folder, Corepack reads that declaration and either uses a cached copy or fetches the correct version automatically. If you accidentally try to use the wrong package manager for a project, Corepack tells you so, which prevents a common source of broken installs.

For teams working in environments without internet access, Corepack has an offline mode. You can pre-download a package manager archive on a machine that has network access, store it alongside your code, and then point Corepack at that file when setting up an offline system.

Corepack ships with Node.js versions 14.19 through 24, so for most developers it is already available. You activate it by running "corepack enable" once, and after that it works quietly in the background. It supports Yarn, pnpm, and npm. The project is open source and part of the Node.js ecosystem.