Uninstall packages completely from a project - manually or automatically
Europe’s developer-focused job platform
Let companies apply to you
Developer-focused, salary and tech stack upfront.
Just one profile, no job applications!
This article is based on Node v16.15.1 and NPM 8.11.0.
Installing and uninstalling dependencies are core parts of working with any Node.js project. If you are just starting with Node.js, have a look at this article - how to install npm packages.
💰 The Pragmatic Programmer: journey to mastery. 💰 One of the best books in software development, sold over 200,000 times.
There are two ways to uninstall packages - manually or automatically.
To uninstall a package, you have to remove it from your
node_modules folder (that's where the code lives), and from
package.json (listed there as a project dependency).
If you only remove it in the
node_modules folder and run
npm install it will be reinstalled, and if you only remove the package entry in the
package.json the package still exists in the
But don't worry. The
npm uninstall command will do both of it. Follow these steps for uninstalling dependencies:
npm uninstall <package1> <package2>
After successfully running the command, the NPM CLI will uninstall the package and print information to the terminal about how many packages were removed. Uninstalling removes the specified package, and all the packages it used internally as dependencies.
package.json, this depends on your installed npm version. Since npm version 5 (released in 2017) installing or uninstalling a dependency will update the
package.jsonautomatically. Previously it was required when installing a package to add the
--saveflag to add the package entry in package.json.
If you've installed a package globally, you can uninstall it by passing the
-g flag when uninstalling. For example, if you have Gatsby CLI globally installed and want to remove it:
npm uninstall -g gatsby
A helpful command is
npm prune, which cleans extraneous packages in your
node_modules folder. More details can be found in a future article.
node_modulesin version control.
Thanks for reading and if you have any questions, use the comment function or send me a message @mariokandut.
If you want to know more about Node, have a look at these Node Tutorials.
HeyNode, NPM Documentation - install, NPM Documentation - uninstall
Never miss an article.