Yarn - remove package best practices

If you want to remove a package using Yarn should you:

  1. run yarn remove [package]

or

  1. delete it from package.json and run yarn install

Do both work the same? Will #2 update yarn.lock?

3 Answers

If you run yarn remove [package] it will remove the package from node_modules and also from the yarn.lock file.

If you manually delete from package.json and then run yarn install, the deleted package is not installed and the yarn.lock file is not updated.

5

When you remove with Yarn by running the first approach (#1).

yarn remove [package]

Both your entries from lockfile and package.json are removed. Look out for this message in the terminal.

$ yarn remove x2js
yarn remove v0.27.5
[1/2] Removing module x2js...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
Done in 2.34s.

The new file won't have the package.

If you follow the second (#2) approach and delete it from package.json and run:

yarn install

There will we no effect on your lockfile.

So it is better to remove packages using the first approach (#1).

If you have deleted some package(s) directly from package.json and don't know what was there then your lockfile is not up to date.

I would suggest you delete the yarn.lock file . and then run yarn install. This way, you will get an updated yarn.lock file.

Best way to remove any package is

yarn remove "your package name"

Your package name should be same as your package.json file

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like