Uninstall/Remove package using Yarn

Uninstall/Remove package using Yarn

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

Yarn ( Yet Another Resource Negotiator ) is a package manager just like NPM which helps us to install and manage dependencies in our projects.

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

Approach 1: yarn remove package

To remove a package from a project the easy and simple way is we just have to run:

yarn remove [package name]

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

Approach 2: Deleting it Manually

If you remove it manually by deleting it from the package.json file and then run:

yarn install

This will reinstall the node_modules again without the deleted package.

However, it will not update the yarn.lock file.

So to resolve this issue, you have to first delete the package entry from your package.json file and then delete the yarn.lock file and after that run yarn install

This time it will reinstall all your node_modules and update the yarn.lock file too.

Conclusion: So you can see, the best practice would be Approach 1 (yarn remove package name). It will delete and update all the files with just one command.

Related Topics:

How To Clear Cache In Npm?