yarn-workspacesyarn-v4

Migrate my yarn project from yarn@1.22.21 to yarn@4.1.1


My project is using yarn@1.22.21 and node 16.x.x i want to update my node version to node 20 and i new that node 20 works with yarn@4.1.1.

When i went to yarn page migration https://yarnpkg.com/migration/guide and used corepack used yarn@4.1.1 as the guide say Run corepack enable to activate Corepack, i got this error:

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

How can i update my project yarn version?


Update: after some testing and some try and error i find that the first thing you need to do after setting your node verstion to 20 is to use the command yarn set version stable before proceeding with any other steps.


Solution

  • This maybe you have ever install yarn globally.

    you can do step as follow:

    1、which yarn, confirm where the Yarn you are currently executing is located,

    it maybe console output: /opt/homebrew/bin/yarn

    2、npm uninstall -g yarn

    3、corepack enable or corepack yarn

    then you'll find the problem is missing.

    after that, when you execute which yarn to check,

    it'll console output: /node/v20.11.1/bin/yarn