corepack icon indicating copy to clipboard operation
corepack copied to clipboard

npm global install / uninstall blocked in yarn/pnpm project if npm enabled

Open MikeMcC399 opened this issue 8 months ago • 2 comments

Current behavior

If Corepack is enabled for npm and an attempt is made to install Corepack globally when the current working directory (or hierachy above) contains a package.json with packageManager set to yarn or pnpm, then the installation of Corepack fails with a message similar to:

This project is configured to use yarn because /tmp/tmp.XVBPXUZMhT/package.json has a "packageManager" field

This also means that the instructions in the README > Manual Installs > Update Corepack using npm section fail in this situation.

Expected behavior

Global install of Corepack via npm should not be blocked when executing npm install -g or npm uninstall -g in a project configured for Yarn or pnpm and when Corepack is enabled for npm.

Alternatively, the restriction should be documented in the README.

Versions

Corepack 0.31.0 Ubuntu 24.04.2 LTS Node.js 22.14.0 LTS

Steps to reproduce

export DEBUG=corepack
rm -rf ~/.cache/node/corepack
corepack enable npm
cd $(mktemp -d)
corepack use yarn
corepack -v
npm install -g corepack@latest
corepack -v

Logs

$ export DEBUG=corepack
rm -rf ~/.cache/node/corepack
corepack enable npm
cd $(mktemp -d)
corepack use yarn
corepack -v
npm install -g corepack@latest
corepack -v
Installing [email protected] in the project...
  corepack Installing [email protected] from https://repo.yarnpkg.com/4.8.0/packages/yarnpkg-cli/bin/yarn.js +0ms
  corepack Downloading to /home/mike/.cache/node/corepack/v1/corepack-5075-81fd1e1.d12d +1ms
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +280ms
  corepack No LastKnownGood version found in Corepack home. +1ms
  corepack Download and install of [email protected] is finished +0ms
  corepack Checking /tmp/tmp.5Ay532aF12/package.json +0ms
  corepack Checking /tmp/package.json +0ms
  corepack Checking /package.json +0ms

➤ YN0000: · Yarn 4.8.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: └ Completed
➤ YN0000: · Done in 0s 52ms
0.31.0
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +0ms
  corepack No LastKnownGood version found in Corepack home. +3ms
  corepack Search for default version: found in remote registry [email protected]+sha512.3dc9c50ba813a3d54393155a435fe66404b72685ab0e3008f9ae9ed8d81f6104860f07ed2656dd5748c1322d95f3140fa9b19c59a6bba7750fd12285f81866da +1s
  corepack Setting [email protected]+sha512.3dc9c50ba813a3d54393155a435fe66404b72685ab0e3008f9ae9ed8d81f6104860f07ed2656dd5748c1322d95f3140fa9b19c59a6bba7750fd12285f81866da as Last Known Good version +0ms
  corepack LastKnownGood file would be located at /home/mike/.cache/node/corepack/lastKnownGood.json +1ms
  corepack Checking /tmp/tmp.5Ay532aF12/package.json +1ms
This project is configured to use yarn because /tmp/tmp.5Ay532aF12/package.json has a "packageManager" field
0.31.0

MikeMcC399 avatar Mar 29 '25 08:03 MikeMcC399

Sounds good to me. Should apply to both -g and --global.

styfle avatar Mar 30 '25 02:03 styfle

Should apply to both -g and --global.

Apart from the option aliases, each command has a whole bunch of aliases as well:

MikeMcC399 avatar Mar 30 '25 05:03 MikeMcC399