Yarn - remove package best practices
Solution 1:
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.
Solution 2:
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.