How to initialize a cloned yarn project
Rohan Villoth
Posted on June 15, 2021
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:
For Yarn 1.x
Make sure yarn is installed globally:
npm install -g yarn
Then, move to project folder and upgrade to latest in yarn 1.x branch:
cd ~/path/to/project
yarn set version latest
Install the project dependencies:
yarn install
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 build
, yarn dev
, yarn start
, 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.
For Yarn 2.x
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:
yarn --version
Now, follow the same steps for 1.x. For more info, refer to Yarn 2 docs.
Downgrade from Yarn 2.x to 1.x
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.
Credits & Sources
- Yarn Documentation
- Cover image from Get Logo Vector
Posted on June 15, 2021
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.