How to Uninstall npm packages

We typically install an npm package as follows:

npm install <package_name>
Code language: Bash (bash)

But how do we uninstall an npm package?

How to uninstall an npm package

This will uninstall an npm package that was installed in your project.

Just make sure to run the command from the root directory of your project.

npm uninstall <package_name>
Code language: Bash (bash)

This will remove the package from the node_modules directory and will also remove the reference to it from the package.json file.

How to uninstall a devDependency

If you have a package installed in the devDependency section of your package.json, then you can uninstall it as follows:

npm uninstall -D <package_name>
Code language: Bash (bash)

How to uninstall a global npm package

Sometimes we install npm packages globally, so that we can use them as command-line tools, or if we want them accessible to all projects.

This can be achieved as follows:

npm uninstall -g <package_name>
Code language: Bash (bash)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments