Home > Web Front-end > JS Tutorial > How to Migrate from Classic Yarn to &#Modern Yarn&# Without Losing Your Mind

How to Migrate from Classic Yarn to &#Modern Yarn&# Without Losing Your Mind

DDD
Release: 2025-01-04 17:14:39
Original
732 people have browsed it

I spent most of my afternoon dealing with yarn versioning.
So here's the deal: Yarn used to be installed globally via npm i -g yarn or tools like brew or choco. Every project you worked on would use that global installation to manage dependencies, and it would usually install version 1, aka "classic.". Also the dreaded 1.22.1 (at least for me).
The issue with that is, if you updated yarn in the version 1 branch, old projects could break because of compatibility problems. Also, another afternoon for me on a different project. Those afternoons that could’ve been better spent drinking coffee. ☕️

Enter "Modern yarn" – starting from version 2 and now at version 4. The cool thing with this version is that it's installed per project via Corepack (a Node tool that handles different versions). This means each project can use its own version of yarn, which is great for avoiding compatibility issues. But to make this work, you’ve got to uninstall yarn globally and reinstall it using Corepack.
More info about Corepack here.

Here’s how to remove classic yarn in steps:

Step 1️⃣:
Uninstall Classic Yarn

Note: uninstall yarn based on how it was originally installed:

On macOS with Homebrew:

$ brew uninstall yarn
Copy after login

If it was installed via npm:

$ npm remove yarn --global
Copy after login

Step 2️⃣: Check Uninstallation ?

Make sure yarn is no longer installed globally by checking the version:

$ yarn --version
Copy after login

You should get something like this after it has been properly uninstalled.

How to Migrate from Classic Yarn to

If after uninstalling you still get the previous version, try this:

# On Mac:
$ which yarn

# On Win:
$ 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

Copy after login

Step 3️⃣: Corepack ?
Install and enable corepack

Now install Corepack, if it is not available on your machine. And because it's still expertimental, enable it afterwards.

How to check if you have Corepack?

How to Migrate from Classic Yarn to

If you don't have it installed then:

$ npm install corepack --global
Copy after login

Enable Corepack

$ corepack enable
Copy after login

Now, use modern Yarn in your project (folder):

$ cd projects/my-project # choose your path
$ yarn set version stable
$ yarn install
Copy after login

Switch a project

If you want to migrate a project to modern yarn, try this:

$ cd projects/my-project # choose your path
$ yarn set version stable
Copy after login

or via corepack:

$ corepack use yarn@latest
Copy after login

You could even install "Modern yarn" in a new version globally, if you want:

$ corepack install --global yarn@latest
Copy after login

Personally, after doing all of this, I was still having issues ? (the version remain 1.22.1). This is what worked for me:

How to Migrate from Classic Yarn to

But what's Yarn Berry?

Yarn Berry is a package management system for Node.js, created by Mäl Nison, the main developer of Yarn v1. The official version (v2) has been released since January 25, 2020, and is now being adopted by large open source repositories such as Babel. Yarn Berry is managed by source code in the GitHub repository.
This is a post by @solleedata explaining Yarn Berry in more detail, from which the description above is copied.

The above is the detailed content of How to Migrate from Classic Yarn to &#Modern Yarn&# Without Losing Your Mind. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template