nodejs / nodejs/corepack

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

Open
#690 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.8k
Forks
279
Avg merge
1h 47m
Merged PRs (30d)
2

Description

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 yarn@4.8.0 in the project...
  corepack Installing yarn@4.8.0 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 yarn@4.8.0 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 npm@11.2.0+sha512.3dc9c50ba813a3d54393155a435fe66404b72685ab0e3008f9ae9ed8d81f6104860f07ed2656dd5748c1322d95f3140fa9b19c59a6bba7750fd12285f81866da +1s
  corepack Setting npm@11.2.0+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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction commands in the issue: enable npm, create a Yarn project with corepack use yarn, and run npm install -g corepack@latest or uninstall it. Read the README's “Manual Installs > Update Corepack using npm” section and trace the global-install behavior. Done means global npm install and uninstall are not blocked in Yarn or pnpm projects, or the restriction is clearly documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.