Uninstalling npm packages with npm uninstall
Learn how to properly uninstall an npm Node package, whether it is installed locally or globally.
To uninstall a package that was previously installed locally in the node_modules
folder, you can run the following command from the project’s root folder:
1 | npm uninstall <package-name> |
This will not only remove the package from the node_modules
folder but also remove its reference from the package.json
file.
If the package was installed as a development dependency and listed in the devDependencies section of the package.json
file, you need to use the -D
or --save-dev
flag to properly remove it from the file:
1 | npm uninstall -D <package-name> |
Alternatively, if the package is installed globally, you should add the -g
or --global
flag:
1 | npm uninstall -g <package-name> |
For example, to uninstall webpack globally, you would run the command:
1 | npm uninstall -g webpack |
It’s worth mentioning that you can execute this command from any location on your system, as the current folder does not affect the uninstallation process.
tags: [“npm”, “package management”, “uninstall”, “global package”, “local package”]