corepack
Manage Node.js package managers
TLDR
Add the Corepack shims to the Node.js installation directory to make them available as global commands
Add the Corepack shims to a specific directory
Remove the Corepack shims from the Node.js installation directory
Prepare a specific package manager
Prepare the package manager configured for the project in the current path
Use a package manager without installing it as a global command
Install a package manager from the specified archive
Display help for a subcommand
SYNOPSIS
corepack enable|disable|prepare|use [manager[@version]] [options]
PARAMETERS
enable
Install shims for specified package manager(s); use --all for all supported.
disable
Remove shims for specified package manager(s); use --all for all.
prepare
Download, verify, and prepare a package manager binary (--which shows path).
use
Activate a specific package manager version for the current project.
--install-directory
Custom directory for shim installation (default: ~/.corepack).
--silent
Suppress all logging output.
--json
Format output as JSON.
--config
Path to corepack configuration file.
--help
Display help information.
--version
Print corepack version.
DESCRIPTION
Corepack is a zero-runtime-dependency tool bundled with Node.js starting from version 16.9.0. It serves as a bridge between Node.js projects and package managers like npm, yarn, and pnpm, allowing automatic installation and use of specific package manager versions without global installations or npx.
Corepack downloads and caches binaries on-demand, ensuring reproducible builds across teams and CI/CD pipelines. By specifying a packageManager field in package.json (e.g., "yarn@3.2.0"), projects pin exact versions. Running corepack enable installs executable shims into your PATH (default: ~/.corepack), enabling direct use of yarn, pnpm, etc., with the project's specified version.
Key benefits include eliminating "works on my machine" issues, reducing dependencies, and supporting monorepos. It proxies commands like corepack yarn install even without shims. Corepack verifies checksums for security and supports offline mode after caching.
While powerful, it's opt-in and requires modern Node.js. Disable with corepack disable to revert.
CAVEATS
Requires Node.js 16.9.0+; shims may need shell rehash (e.g., hash -r); experimental until Node 16.17.0; caching uses disk space (~100MB per manager).
PACKAGE.JSON FIELD
Use "packageManager": "yarn@3.6.0" or "corepack": { "yarn": "3.6.0" } to pin versions.
DIRECT INVOCATION
corepack yarn@stable install or corepack pnpm@latest add lodash works without enable.
HISTORY
Introduced experimentally in Node.js v16.9.0 (Sep 2021). Stabilized in v16.17.0 (Oct 2022). Expanded support for pnpm in v18+. Default-disabled until manually enabled.


