node.jsyarnpkgcorepack

Node corepack is ignoring packageManager and won't let me set yarn version


I've cloned a project which uses Yarn 1.x and am trying to run it, but I can't find a way to get the right version of Yarn. I think I must be missing something.

Commented Terminal session:

# using node16.18.0
$ nvm use v16
Now using node v16.18.0 (npm v8.19.2)

# start with no yarn installed
$ yarn --version
zsh: command not found: yarn

# package.json has packageManager set for Yarn v1.22.19
$ cat package.json | grep packageManager
  "packageManager": "yarn@1.22.19"

# enable corepack, and it ignores the packageManager version
$ corepack enable
$ yarn --version
3.2.4

# manually ask corepack to use v1.22.19, but it again ignores this
$ corepack prepare yarn@1.22.19 --activate
Preparing yarn@1.22.19 for immediate activation...
$ yarn --version
3.2.4

# manually ask corepack to run yarn 1.22.19, but it again ignores it
$ corepack yarn@1.22.19 --version
3.2.4

So using Corepack I don't seem to be able to convince it to use version of Yarn.

In addition installing using npm install -g also doesn't seem to work correctly.

# disable corepack so there's no yarn installed
$ corepack disable
$ yarn --version
zsh: command not found: yarn

# install yarn v1.22.19
$ npm install -g yarn@1.22.19

added 1 package, and audited 2 packages in 326ms

found 0 vulnerabilities

# somehow it's installed 3.2.4 again
$ yarn --version
3.2.4

Solution

  • This doesn't address the corepack issue but I have been able to get npm install -g yarn@1.22.19 to work. I found a file ~/.yarnrc.yml which had a version 3.2.4 in it. I'm not sure if the npm yarn version was actually incorrect, or if it just used ~/.yarnrc.yml as its source of truth incorrectly. But regardless when I deleted this file and reinstalled yarn globally at the desired version it worked correctly.