Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 28, 2026·3 min de lectura

Corepack — Node.js Package Manager Version Manager

Corepack is a Node.js tool that manages package manager versions (npm, yarn, pnpm) per project, ensuring every contributor uses the exact same version without manual installs.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Corepack Overview
Comando de instalación directa
npx -y tokrepo@latest install aa43e0ab-8a83-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

Corepack is a zero-install manager for JavaScript package managers that ships with Node.js. It reads the packageManager field in package.json to automatically download and use the correct version of npm, yarn, or pnpm, eliminating version drift across development teams.

What Corepack Does

  • Automatically downloads and caches the correct package manager version specified in package.json
  • Intercepts calls to yarn, pnpm, and npm to transparently shim the correct binary
  • Enforces version consistency across all contributors without requiring manual installs
  • Supports pinning exact package manager versions per project via the packageManager field
  • Ships with Node.js 16.9+ and requires only a one-time corepack enable to activate

Architecture Overview

Corepack installs lightweight shim scripts for each supported package manager in the Node.js bin directory. When you run yarn or pnpm, the shim reads packageManager from the nearest package.json, downloads that exact version to a local cache if missing, and forwards the command. The cache is shared across projects, so identical versions are downloaded only once.

Self-Hosting & Configuration

  • Enable with corepack enable (may require sudo on system Node.js installs)
  • Add to package.json: "packageManager": "pnpm@9.1.0" to pin the version
  • Use corepack prepare pnpm@9.1.0 --activate to pre-download and set a default
  • Set COREPACK_HOME environment variable to customize the cache directory
  • In CI, run corepack enable before npm install or yarn install for consistent builds

Key Features

  • Ships with Node.js out of the box, no additional installation required
  • Transparent shimming means existing scripts and CI pipelines work without changes
  • Supports npm, yarn (Classic and Berry), and pnpm with automatic version resolution
  • Offline-capable once versions are cached; useful for air-gapped environments
  • Hash verification ensures downloaded package managers match expected checksums

Comparison with Similar Tools

  • nvm / fnm — Manage Node.js versions; Corepack manages package manager versions within a Node.js install
  • volta — Manages both Node.js and package manager versions; Corepack is lighter and ships with Node.js
  • asdf / mise — General version managers for multiple tools; Corepack is Node.js-specific and zero-install
  • npx — Runs packages without installing; Corepack pins and caches the package manager itself
  • ni — Smart package manager dispatcher; Corepack ensures version consistency rather than just detecting which manager to use

FAQ

Q: Is Corepack enabled by default in Node.js? A: Corepack ships with Node.js 16.9+ but is not enabled by default. Run corepack enable once to activate the shims.

Q: Does Corepack manage npm versions? A: Corepack can manage npm versions when specified in packageManager, but npm management is opt-in since npm already ships with Node.js.

Q: What happens if the specified version is not cached? A: Corepack downloads it automatically on first use and caches it for subsequent runs.

Q: Can I use Corepack in Docker builds? A: Yes. Add RUN corepack enable in your Dockerfile before running package install commands. In Node.js 20+ images, Corepack is already present.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados