{ "type": "module", "source": "doc/api/corepack.md", "introduced_in": "v14.19.0", "meta": { "added": [ "v16.9.0", "v14.19.0" ], "changes": [] }, "stability": 1, "stabilityText": "Experimental", "miscs": [ { "textRaw": "Corepack", "name": "Corepack", "introduced_in": "v14.19.0", "type": "misc", "meta": { "added": [ "v16.9.0", "v14.19.0" ], "changes": [] }, "stability": 1, "stabilityText": "Experimental", "desc": "
Corepack is an experimental tool to help with\nmanaging versions of your package managers. It exposes binary proxies for\neach supported package manager that, when called, will identify whatever\npackage manager is configured for the current project, download it if needed,\nand finally run it.
\nDespite Corepack being distributed with default installs of Node.js, the package\nmanagers managed by Corepack are not part of the Node.js distribution and:
\nThis feature simplifies two core workflows:
\nIt eases new contributor onboarding, since they won't have to follow\nsystem-specific installation processes anymore just to have the package\nmanager you want them to.
\nIt allows you to ensure that everyone in your team will use exactly the\npackage manager version you intend them to, without them having to\nmanually synchronize it each time you need to make an update.
\nDue to its experimental status, Corepack currently needs to be explicitly\nenabled to have any effect. To do that, run corepack enable
, which\nwill set up the symlinks in your environment next to the node
binary\n(and overwrite the existing symlinks if necessary).
From this point forward, any call to the supported binaries will work\nwithout further setup. Should you experience a problem, run\ncorepack disable
to remove the proxies from your system (and consider\nopening an issue on the Corepack repository to let us know).
The Corepack proxies will find the closest package.json
file in your\ncurrent directory hierarchy to extract its \"packageManager\"
property.
If the value corresponds to a supported package manager, Corepack will make\nsure that all calls to the relevant binaries are run against the requested\nversion, downloading it on demand if needed, and aborting if it cannot be\nsuccessfully retrieved.
\nYou can use corepack use
to ask Corepack to update your local\npackage.json
to use the package manager of your choice:
corepack use pnpm@7.x # sets the latest 7.x version in the package.json\ncorepack use yarn@* # sets the latest version in the package.json\n
",
"type": "module",
"displayName": "Configuring a package"
},
{
"textRaw": "Upgrading the global versions",
"name": "upgrading_the_global_versions",
"desc": "When running outside of an existing project (for example when running\nyarn init
), Corepack will by default use predefined versions roughly\ncorresponding to the latest stable releases from each tool. Those versions can\nbe overridden by running the corepack install
command along with the\npackage manager version you wish to set:
corepack install --global yarn@x.y.z\n
\nAlternately, a tag or range may be used:
\ncorepack install --global pnpm@*\ncorepack install --global yarn@stable\n
",
"type": "module",
"displayName": "Upgrading the global versions"
},
{
"textRaw": "Offline workflow",
"name": "offline_workflow",
"desc": "Many production environments don't have network access. Since Corepack\nusually downloads the package manager releases straight from their registries,\nit can conflict with such environments. To avoid that happening, call the\ncorepack pack
command while you still have network access (typically at\nthe same time you're preparing your deploy image). This will ensure that the\nrequired package managers are available even without network access.
The pack
command has various flags. Consult the detailed\nCorepack documentation for more information.
The following binaries are provided through Corepack:
\nPackage manager | \nBinary names | \n
---|---|
Yarn | \nyarn , yarnpkg | \n
pnpm | \npnpm , pnpx | \n
While Corepack could support npm like any other package manager, its\nshims aren't enabled by default. This has a few consequences:
\nIt's always possible to run a npm
command within a project configured to\nbe used with another package manager, since Corepack cannot intercept it.
While npm
is a valid option in the \"packageManager\"
property, the\nlack of shim will cause the global npm to be used.
npm prevents accidentally overriding the Corepack binaries when doing a global\ninstall. To avoid this problem, consider one of the following options:
\nDon't run this command; Corepack will provide the package manager\nbinaries anyway and will ensure that the requested versions are always\navailable, so installing the package managers explicitly isn't needed.
\nAdd the --force
flag to npm install
; this will tell npm that it's fine to\noverride binaries, but you'll erase the Corepack ones in the process. (Run\ncorepack enable
to add them back.)