How to configure Yarn Berry?

Dec 04, 2025

Leave a message

Hey there! As a yarn supplier, I've been getting a bunch of questions lately about how to configure Yarn Berry. So, I thought I'd put together this blog post to share my knowledge and help you out. Whether you're a newbie or just looking to brush up on your skills, this guide is for you.

First things first, let's talk about what Yarn Berry is. Yarn Berry is the latest version of the Yarn package manager, and it comes with a whole bunch of new features and improvements. One of the biggest advantages of Yarn Berry is its speed. It's significantly faster than the previous version, which means you can get your projects up and running in no time.

Another great feature of Yarn Berry is its support for plug-ins. With plug-ins, you can extend the functionality of Yarn Berry and customize it to fit your specific needs. There are a ton of plug-ins available, so you're sure to find one that works for you.

Now, let's get into the nitty-gritty of how to configure Yarn Berry. The first step is to install it. You can do this by running the following command in your terminal:

npm install -g yarn

Once you've installed Yarn, you can initialize a new project by running the following command:

Plant-based Mult-functional FabricPlant-based Mult-functional Fabric

yarn init -2

The -2 flag tells Yarn to use the Berry version. After you've initialized your project, you'll see a package.json file in your project directory. This file contains all the information about your project, including its dependencies.

Next, you'll want to configure your .yarnrc.yml file. This file is used to customize the behavior of Yarn Berry. You can create this file in the root of your project directory. Here's an example of what your .yarnrc.yml file might look like:

nodeLinker: node-modules

The nodeLinker option tells Yarn how to link your project's dependencies. In this case, we're using node-modules, which is the traditional way of linking dependencies in Node.js projects.

If you want to use a custom registry, you can add the following line to your .yarnrc.yml file:

npmRegistryServer: "https://registry.npmjs.org"

This will tell Yarn to use the specified registry when downloading packages.

Now, let's talk about how to add dependencies to your project. You can do this by running the following command:

yarn add <package-name>

For example, if you want to add the lodash package to your project, you can run the following command:

yarn add lodash

Yarn will automatically download the package and add it to your package.json file.

If you want to add a dev dependency, you can use the --dev flag:

yarn add <package-name> --dev

Dev dependencies are only used during development and are not included in your production build.

One of the cool features of Yarn Berry is its support for workspaces. Workspaces allow you to manage multiple packages in a single repository. To enable workspaces, you need to add the following line to your package.json file:

{
  "workspaces": ["packages/*"]
}

This tells Yarn to look for packages in the packages directory. You can then create subdirectories in the packages directory for each of your packages.

Now, let's talk about some of the other useful commands in Yarn Berry. If you want to update all your dependencies to their latest versions, you can run the following command:

yarn up

If you want to remove a dependency, you can run the following command:

yarn remove <package-name>

And if you want to run a script defined in your package.json file, you can run the following command:

yarn run <script-name>

For example, if you have a start script defined in your package.json file, you can run it by running the following command:

yarn run start

That's pretty much the basics of how to configure Yarn Berry. Of course, there's a lot more you can do with it, but this should give you a good starting point.

As a yarn supplier, I also want to mention some of the great products we offer. Check out our Polyester Yarn POY 37Dtex/72filament Manufacturers for high-quality polyester yarn. We also have Plant-based Mult-functional Fabric for those looking for eco-friendly options. And if you're interested in PBT yarn, check out our Pbt Yarn China products.

If you're interested in purchasing any of our products or have any questions about Yarn Berry configuration, feel free to reach out to us. We're here to help you with all your yarn needs.

In conclusion, Yarn Berry is a powerful and flexible package manager that can make your development process a lot easier. By following the steps outlined in this blog post, you should be able to configure Yarn Berry for your projects and start taking advantage of its features.

References:

  • Yarn official documentation
  • Various online tutorials and forums