node.jsnpmyarnpkgpnpmcorepack

How to disable auto-setting of `packageManager` when corepack is enabled


In Node.js, when corepack is enabled, any yarn, pnpm or npm command will auto-set packageManager field in package.json.

This is a breaking change for some projects, since having packageManager means you can't use one packager for the install (npm i) and another packager for running scripts (yarn start). It would output the following error:

UsageError: This project is configured to use npm because ./package.json has a "packageManager" field

How to disable this behaviour? I'd like to keep using corepack, since it's nice, but I'd prefer to avoid setting a particular packageManager in my package.json.

Cheers.


Solution

  • You can set the environment variable COREPACK_ENABLE_AUTO_PIN to 0 in order to disable this behavior (from corepack readme).