corepack icon indicating copy to clipboard operation
corepack copied to clipboard

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

Open Tobbe opened this issue 1 year ago • 5 comments

Issue

@Tobbe ➜ /workspaces/redwood (main) $ yarn -v
1.22.22
@Tobbe ➜ /workspaces/redwood (main) $ yarn
error This project's package.json defines "packageManager": "[email protected]". 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": "[email protected]". 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 [email protected]...
@Tobbe ➜ /workspaces/redwood (main) $ yarn -v
1.22.22
@Tobbe ➜ /workspaces/redwood (main) $ corepack install -g yarn@latest
Installing [email protected]...
@Tobbe ➜ /workspaces/redwood (main) $ yarn -v
1.22.22
@Tobbe ➜ /workspaces/redwood (main) $ yarn
error This project's package.json defines "packageManager": "[email protected]". 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

Tobbe avatar Jul 02 '24 06:07 Tobbe

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

aduh95 avatar Jul 02 '24 08:07 aduh95

@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) $ 

Tobbe avatar Jul 02 '24 08:07 Tobbe

It seems to work after opening a new terminal session.

michcio1234 avatar Nov 06 '24 12:11 michcio1234

For anyone else landing here - in my case the root cause was having Volta installed. I work in multiple repositories, some use corepack and others Volta, but Volta silently breaks corepack, so I need to switch between them manually when changing working directories.

  • https://github.com/volta-cli/volta/issues/987

donmccurdy avatar Jan 30 '25 19:01 donmccurdy

This happens for me when using devcontainers to install a Yarn 3 project.

Permalink: https://github.com/fulldecent/github-pages-template/commit/cb834fd1f3262c7ee159955b6654545715e0b951


Here is the Voodoo I experience:

vscode ➜ /workspaces/github-pages-template (main) $ corepack enable
vscode ➜ /workspaces/github-pages-template (main) $ which yarn
/usr/local/share/nvm/versions/node/v22.14.0/bin/yarn
vscode ➜ /workspaces/github-pages-template (main) $ yarn
error This project's package.json defines "packageManager": "[email protected]". 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.
vscode ➜ /workspaces/github-pages-template (main) $ /usr/local/share/nvm/versions/node/v22.14.0/bin/yarn
➤ YN0000: · Yarn 4.6.0
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: · Done with warnings in 0s 221ms
vscode ➜ /workspaces/github-pages-template (main) $ command yarn
error This project's package.json defines "packageManager": "[email protected]". 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.

Hack

I need this to work without opening a new terminal. Here is my workaround:

$NVM_INC/../../bin/yarn

or

alias yarn=$NVM_INC/../../bin/yarn

fulldecent avatar Apr 17 '25 15:04 fulldecent