nodejs / corepack

Zero-runtime-dependency package acting as bridge between Node projects and their package managers
MIT License
2.31k stars 145 forks source link

`corepack enable` exits successfully (exit code 0), but isn't actually enabled #507

Open Tobbe opened 3 days ago

Tobbe commented 3 days ago

Issue

@Tobbe ➜ /workspaces/redwood (main) $ yarn -v
1.22.22
@Tobbe ➜ /workspaces/redwood (main) $ yarn
error This project's package.json defines "packageManager": "yarn@4.3.0". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
@Tobbe ➜ /workspaces/redwood (main) $ corepack enable
@Tobbe ➜ /workspaces/redwood (main) $ yarn
error This project's package.json defines "packageManager": "yarn@4.3.0". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.
@Tobbe ➜ /workspaces/redwood (main) $ corepack prepare
Preparing yarn@4.3.0...
@Tobbe ➜ /workspaces/redwood (main) $ yarn -v
1.22.22
@Tobbe ➜ /workspaces/redwood (main) $ corepack install -g yarn@latest
Installing yarn@4.3.1...
@Tobbe ➜ /workspaces/redwood (main) $ yarn -v
1.22.22
@Tobbe ➜ /workspaces/redwood (main) $ yarn
error This project's package.json defines "packageManager": "yarn@4.3.0". However the current global version of Yarn is 1.22.22.

Presence of the "packageManager" field indicates that the project is meant to be used with Corepack, a tool included by default with all official Node.js distributions starting from 16.9 and 14.19.
Corepack must currently be enabled by running corepack enable in your terminal. For more information, check out https://yarnpkg.com/corepack.

Every command (except running just yarn) above exited with code 0. But none of them seems to actually do anything.

Expected behavior

Ideally corepack enable would work, and yarn would switch to version 4.3, but at the very least some kind of error message would be useful when corepack can't actually be enabled.

Additional Info

corepack yarn -v correctly prints out 4.3.0

Reproduction

  1. Go to https://github.com/redwoodjs/redwood
  2. Press . on your keyboard to open the redwood repo in an in-browser editor
  3. Set up a new codespace
  4. In the terminal, run corepack enable and yarn install

Workaround

Always use corepack yarn instead of just yarn

aduh95 commented 3 days ago

Is maybe yarn an alias? What does command -v yarn returns? What about alias yarn?

Tobbe commented 3 days ago
@Tobbe ➜ /workspaces/redwood (main) $ command -v yarn
/usr/bin/yarn
@Tobbe ➜ /workspaces/redwood (main) $ alias yarn
bash: alias: yarn: not found
@Tobbe ➜ /workspaces/redwood (main) $ realpath `which yarn`
/usr/local/share/nvm/versions/node/v20.14.0/lib/node_modules/corepack/dist/yarn.js
@Tobbe ➜ /workspaces/redwood (main) $