|$ curl https://forge-ai.dev/api/markdown?path=docs/npm/corepack
$cat docs/corepack.md
updated Today·18-24 min read·published

Corepack

CorepackpnpmYarnCIIntermediate🎯Free Tools
Introduction

Corepack is a Node.js tool that manages package manager binaries for Yarn and pnpm (and historically other shims). Instead of asking every developer to npm i -g pnpm at a random version, the repo declares packageManager in package.json and Corepack downloads that exact release on first use.

That single field is the contract between local machines, Docker images, and CI. Pair it with manager choice and best practices.

📝

note

Corepack does not manage Bun or npm itself. npm still ships with Node; Bun is installed separately.
Why Teams Need It
Problem without CorepackWith Corepack
Dev A on pnpm 8, Dev B on pnpm 9 → lockfile thrashEveryone gets packageManager version
Global yarn still Classic v1Berry version pinned per project
CI image drifts from laptopsSame prepare/activate path
"Works on my machine" install scriptsDeterministic manager binary
Enabling Corepack

Corepack ships with Node but is often disabled by default (depending on Node version and distro packaging). Enable it once per machine or image.

enable.sh
Bash
1# Requires a recent Node.js (16.10+ historically; use current LTS)
2node -v
3which corepack
4
5corepack enable
6
7# Optional: pre-download a manager without entering a project
8corepack prepare pnpm@9.15.0 --activate
9corepack prepare yarn@4.5.0 --activate
10
11pnpm --version
12yarn --version

warning

Some Linux distro Node packages strip Corepack. Prefer official Node binaries, fnm/nvm, or Docker node:22 images when Corepack is missing.
packageManager Field

The packageManager field is a string: name@version, optionally with a hash for integrity.

package.json
JSON
1{
2 "name": "acme",
3 "private": true,
4 "packageManager": "pnpm@9.15.0"
5}
package.json (with hash)
JSON
1{
2 "packageManager": "pnpm@9.15.0+sha512.AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
3}
Value exampleMeaning
pnpm@9.15.0Use pnpm 9.15.0 via Corepack
yarn@4.5.0Use Yarn Berry 4.5.0
npm@10.9.0Declared for tooling; npm still comes from Node
set-field.sh
Bash
1# Yarn can write the field when setting version
2yarn set version 4.5.0
3
4# Or set manually / via npm pkg
5npm pkg set packageManager=pnpm@9.15.0
6
7# Verify Corepack respects it from project root
8pnpm --version # should match packageManager

best practice

Pin an exact version (not a range). Ranges defeat the purpose — two machines could still diverge.
Pinning Workflow for Teams
  1. Choose pnpm or Yarn Berry (see compare guide).
  2. Pick a current stable exact version; record it in packageManager.
  3. Commit lockfile + field in the same PR.
  4. Document corepack enable in README / onboarding.
  5. Mirror the same enable + install steps in CI and Docker.
  6. Upgrade manager versions in deliberate PRs (changelog + reinstall).
upgrade-pnpm.sh
Bash
1# Bump pnpm for the whole team
2npm pkg set packageManager=pnpm@9.15.4
3corepack prepare pnpm@9.15.4 --activate
4pnpm install
5git add package.json pnpm-lock.yaml
6git commit -m "chore: bump pnpm to 9.15.4"
CI Usage

Enable Corepack before any pnpm / yarninvocation. Cache the package store separately from Corepack's downloaded shims when possible.

.github/workflows/ci.yml
YAML
1name: ci
2on: [push, pull_request]
3jobs:
4 build:
5 runs-on: ubuntu-latest
6 steps:
7 - uses: actions/checkout@v4
8 - uses: actions/setup-node@v4
9 with:
10 node-version: 22
11 cache: pnpm
12 - run: corepack enable
13 - run: corepack prepare --activate
14 # reads packageManager from package.json when supported
15 - run: pnpm install --frozen-lockfile
16 - run: pnpm test
17 - run: pnpm build
Dockerfile
Dockerfile
1FROM node:22-bookworm-slim AS deps
2WORKDIR /app
3RUN corepack enable
4COPY package.json pnpm-lock.yaml ./
5# packageManager field must be present in copied package.json
6RUN corepack prepare --activate \
7 && pnpm install --frozen-lockfile
8
9FROM node:22-bookworm-slim AS runner
10WORKDIR /app
11COPY --from=deps /app/node_modules ./node_modules
12COPY . .
13CMD ["node", "dist/server.js"]

info

If setup-node cache for pnpm fails before Corepack exists, enable Corepack first, then install, or use pnpm/action-setup with a version matching packageManager.
Corepack + Yarn Berry

Yarn Berry also commits a project-local binary under .yarn/releases. Corepack still helps bootstrap the correct Yarn to run that project. Keep packageManager aligned with the committed release.

yarn-corepack.sh
Bash
1corepack enable
2yarn set version 4.5.0
3# updates packageManager + .yarn/releases
4yarn install --immutable

Deep dive: Yarn Classic vs Berry.

Corepack + pnpm
pnpm-corepack.sh
Bash
1corepack enable
2# package.json already has "packageManager": "pnpm@9.15.0"
3pnpm install --frozen-lockfile
4pnpm --version

Deep dive: pnpm.

Enforcing the Manager

Corepack pins versions; only-allow blocks the wrong tool entirely (e.g. someone running npm install in a pnpm repo).

package.json
JSON
1{
2 "packageManager": "pnpm@9.15.0",
3 "scripts": {
4 "preinstall": "npx only-allow pnpm"
5 }
6}
🔥

pro tip

Combine packageManager + only-allow + a single committed lockfile. That trio eliminates most multi-manager chaos.
Troubleshooting
SymptomCauseFix
corepack: command not foundDistro Node without CorepackInstall official Node / use nvm
Wrong pnpm versionGlobal pnpm shadows Corepackcorepack enable; check PATH order
Network error downloading managerFirewall / registryprepare in build image; allow Node download hosts
CI cache miss every runCache key before enableEnable Corepack, then cache store by lockfile
Hash mismatch on packageManagerCorrupted or wrong hashReset field to name@version and re-prepare
debug.sh
Bash
1type pnpm
2type yarn
3corepack --version
4node -p "process.versions"
5cat package.json | grep packageManager
6# On Unix: ensure Corepack shims win over ~/.local/bin globals
7echo "$PATH"
Security Notes
  • Prefer packageManager with integrity hash when your toolchain supports generating it.
  • Do not download Yarn/pnpm install scripts from random gists when Corepack can fetch signed releases.
  • Keep Node LTS updated — Corepack bugs are fixed in Node releases.
  • In air-gapped CI, vendor the manager tarball and point Corepack at an internal mirror if configured.

danger

Disabling Corepack and installing random global majors is how lockfiles silently churn. Treat manager upgrades like dependency upgrades — PR + CI green.
Checklist
  • corepack enable in onboarding + CI + Docker
  • Exact packageManager in root package.json
  • One lockfile matching that manager
  • only-allow preinstall when enforcing
  • Document Bun separately if used (no Corepack)
  • Bump manager versions in dedicated commits

Community

Get help on Slack, Discord or VIP

Stuck on a guide? Join the community and ask.