Uninstall/Remove package using Yarn

featured Image

In this article, we will learn about the best practices to remove packages using yarn.

What is Yarn ?

Yarn ( Yet Another Resource Negotiator ) is a package manager just like NPM which helps us to install and manage dependencies in our projects. Yarn was developed by Facebook. Yarn is designed to be faster and more reliable than npm and is now used as an alternative by many developers.

Why Uninstall Packages from Node Projects?

Uninstalling packages is important because:

  1. It reduces the size of the project’s dependencies.
  2. It helps to improve the performance of your application.
  3. It helps to keep the project clean and organized by removing unwanted packages from the project.

Now that we know about the Yarn package manager and why we need to remove unwanted packages from our project. Let’s see a few different ways to uninstall packages, depending on your needs.

To remove a package / dependency from our project we can take four approaches:

Uninstalling a Single Package using Yarn

To uninstall a single package from your Node project using Yarn, you can use the following command:

yarn remove [package-name]

This command will remove the package from node_modules and also update the yarn.lockfile.

For example, if you want to remove lodash, you can use the following:

yarn remove lodash

Uninstalling Multiple Packages using Yarn

To uninstall multiple packages at once, you have to pass all the package names as an argument to the yarn remove command.

yarn remove [package-name-one] [package-name-two]..[package-name-n]

For example, if you want to remove lodash and flickity packages together, then we can use the following command:

yarn remove lodash flickity

Uninstalling Packages from a Specific Workspace

Now, if you are working with Yarn Workspace and want to remove a package from a specific workspace, then use the following command:

yarn workspace [workspace-name] remove [package-name]

For example, let’s say you want to remove the lodash package from the client workspace, then we will use the following command:

yarn workspace client remove lodash

Deleting Packages Manually

To delete a package manually, you have to remove the name of the package from the package.json file of your project.

Next, delete your node_modules folder and yarn.lock file.

Once done, you have to reinstall all the packages (without the removed package) in your project using the following command:

yarn install

All the packages will be in your node_modules and you will have an updated yarn.lock file too.

Conclusion:

In this article, we have discussed how to uninstall/remove packages using Yarn. Yarn makes it easy to uninstall single and multiple packages at once with ease. By uninstalling unwanted packages we keep our project clean and improve its performance.

Related Topics:

How To Clear Cache In Npm?

Related Posts

git commands with example

Top 40 Git commands with Examples

GitHub has become an essential tool for developers to manage, store, and collaborate with other developers on software projects. With its simple powerful git-based version control system, GitHub allows users…

Read more
Check GitHub Account in the Terminal

Check GitHub Account in the Terminal

GitHub is an integral tool for developers to store, manage, and collaborate on software projects with other developers. And as we work more and more in the command line it…

Read more
featured Image

How to make list of objects in Netlify CMS using list and object Widget

Here in this Netlify CMS tutorial we will how easily we can make a list of objects using list and object widgets. This will allow us to add multiple objects…

Read more