Being used to npm based projects for years, I encountered a yarn based one yesterday. I've read about yarn before, but never got the chance to work on it until now. So, I searched around to find the basics to get it working. I found it to be pretty similar to npm so far, with a few changes here and there. If you've cloned a project repo already setup with yarn, these are the general instructions to follow:
Make sure yarn is installed globally:
npm install -g yarn
Then, move to project folder and upgrade to latest in yarn 1.x branch:
yarn set version latest
Install the project dependencies:
And the finally, build and/or run the project. Similar to npm based projects, you can check
package.json file in the project folder and find the necessary commands listed there. Should be like
yarn serve, etc.
Another interesting thing to keep in mind is, the yarn equivalents of
npm install --save and
npm install --save-dev are
yarn add and
yarn add --dev, respectively. I found it mentioned on the documentation page of yarn install command.
Yarn 2.x is meant to be installed per project. So, follow the same steps as yarn 1.x described above, but just before
yarn set version latest, run this:
yarn set version berry
Check if yarn is on version 2.x with:
Now, follow the same steps for 1.x. For more info, refer to Yarn 2 docs.
If you're like me and accidentally installed yarn 2.x on a 1.x based project 😅, don't worry! It's nothing a few commands can't fix. Run:
yarn set version classic
And then follow the steps described above for yarn 1.x. The documentation page for yarn set version command describes more ways to set specific versions.