DEV Community

Cover image for How to initialize a cloned yarn project
Rohan Villoth
Rohan Villoth

Posted on

3 1

How to initialize a cloned yarn project

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
Enter fullscreen mode Exit fullscreen mode

Then, move to project folder and upgrade to latest in yarn 1.x branch:

cd ~/path/to/project
yarn set version latest
Enter fullscreen mode Exit fullscreen mode

Install the project dependencies:

yarn install
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Check if yarn is on version 2.x with:

yarn --version
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Cloudinary image

Optimize, customize, deliver, manage and analyze your images.

Remove background in all your web images at the same time, use outpainting to expand images with matching content, remove objects via open-set object detection and fill, recolor, crop, resize... Discover these and hundreds more ways to manage your web images and videos on a scale.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay