Previously, yarn was installed globally via npm i -g yarn
or brew install yarn
/choco install yarn
and every project you are working on uses it to handle it's dependencies. yarn itself will installed in version 1, which is called "classic". If you update yarn in the version 1 branch over time, old projects could become not compatible anymore.
Here is "Modern yarn" kicking in, because it will be installed not globally, it will installed per project with corepack which is a tool from Node to handle different versions. Modern yarn starts from version 2 and is now 4.
Installed per project basis, you can operate your projects with different yarn versions independently – a huge benefit in terms of compatibiliy. But in order to so, you have to remove yarn globally and reinstall it with corepack.
First, uninstall classic yarn by the way you installed it (brew, choco or npm).
# on MacOS with Homebrew
$ brew uninstall yarn
# on Windows with Chocolatey
$ choco uninstall yarn
# if it was installed via Node
$ npm remove yarn --global
If this doesn't help, try this:
# On Mac:
$ which yarn
# On Windows:
$ where yarn
# which/where will tell you, if and where yarn is installed. You get paths. Remove them!
$ rm -rf /usr/local/bin/yarn # use the path from before
$ rm -rf /usr/local/bin/yarnpkg # use the path from before
Now install Corepack, if it is not available on your machine. And because it's still expertimental, enable it afterwards.
$ npm install corepack --global
$ corepack enable
Now, use modern Yarn in your project (folder):
$ cd projects/my-project # choose your path
$ yarn set version stable
$ yarn install
If you want to migrate a project to modern yarn, try this:
$ cd projects/my-project # choose your path
$ yarn set version stable
# or via corepack
$ corepack use yarn@latest
You could even install "Modern yarn" in a new version globally, if you want:
$ corepack install --global yarn@latest
See: https://yarnpkg.com/corepack, https://stackoverflow.com/questions/42334978/how-do-i-uninstall-yarn, https://yarnpkg.com/getting-started/install