Project version of Yarn conflicts with global Yarn version

Hi,

I’m getting an error when I try to run yarn install in a project.

error This project's package.json defines "packageManager": "yarn@4.5.1". However the current global version of Yarn is 1.22.22.

The global version of Yarn was installed for work, and I don’t really want to mess with it. Anyway around this? Thanks

In what context are you running yarn install? I don’t believe the CLI (where you’ve opened this issue) uses yarn. Did you mean to put this in a different category?

The solution is in the instructions of the track.
If you run corepack enable, you should no longer see this issue.

Having a global yarn version at 1.22.22 is fine as yarn set latest will locally (in a project folder) install higher versions using that global version.

The command corepack enable didn’t work for me. It runs without error but has no effect. The solution I found is to chance on package.json to the version of my local yarn, in my case: “packageManager”: “yarn@1.22.22”.

If it runs without error, it has effect.

You should not downgrade yarn in packageManager.

A few things to check:

  • Do you have the latest version of the exercise? If so, what exercise are you trying to do?
  • Can you share the package.json file here so I can have a look if it’s really up-to-date or has other issues?
  • Did you try resetting the exercise via the Web UI and then downloading again?
  • After all the above, have you tried running yarn set latest followed by yarn -v to see if your yarn actually does upgrade to the latest version?
  • Finally, what is your node version? node -v.

It seems the cause lies in Yarn:
$ yarn set latest
yarn run v1.22.22
error Command “set” not found.
info Visit yarn run | Yarn for documentation about this command.

Node:
$ node -v
v20.11.0

As it can be useful for other people, a workaround that is enabling to advance in the exercises is the downgrade. Below, I am getting the latest exercise version (Sept/25) of resistor-color:
$ exercism download --track=typescript --exercise=resistor-color

Downloaded to
…/resistor-color
$ cd ../resistor-color

$ yarn install

error This project’s package.json defines “packageManager”: “yarn@4.5.1”. 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 Corepack | Yarn.

$ corepack enable

$ yarn install

error This project’s package.json defines “packageManager”: “yarn@4.5.1”. 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 Corepack | Yarn.

$ vim package.json

Edited to yarn@1.22.22

$ yarn install
yarn install v1.22.22
info No lockfile found.
[1/5] :mag: Validating package.json…
[2/5] :mag: Resolving packages…
warning @jest/globals > @jest/expect > jest-snapshot > @jest/transform > babel-plugin-istanbul > test-exclude > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning @jest/globals > @jest/expect > jest-snapshot > @jest/transform > babel-plugin-istanbul > test-exclude > glob > inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning jest > @jest/core > jest-config > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > jest-runtime > glob@7.2.3: Glob versions prior to v9 are no longer supported
warning jest > @jest/core > @jest/reporters > glob@7.2.3: Glob versions prior to v9 are no longer supported
[3/5] :truck: Fetching packages…
[4/5] :link: Linking dependencies…
warning “babel-jest > babel-preset-jest > babel-preset-current-node-syntax@1.2.0” has unmet peer dependency “@babel/core@^7.0.0 || ^8.0.0-0”.
warning " > babel-jest@29.7.0" has unmet peer dependency “@babel/core@^7.8.0”.
warning “babel-jest > babel-preset-jest@29.6.3” has unmet peer dependency “@babel/core@^7.0.0”.
[5/5] :hammer: Building fresh packages…
success Saved lockfile.
:sparkles: Done in 19.71s.

Can you please answer my questions?

Can you try corepack yarn -v as well? If this version is different, your local yarn is overwriting corepack.

returns 4.5.1 if package.json has "packageManager": "yarn@4.5.1" and 1.22.22 if it has "yarn@1.22.22"

That’s correct.

All the issues are caused because you have likely manually installed yarn.
If you prefix all the commands with corepack, everything should work as documented.

1 Like