2
33

How to easily Uninstall NPM Package

Reading Time: < 1 minute

There are various things to note on the topic of uninstall NPM package. Here, we will discuss them.

Benefits of Uninstalling NPM Package

  1. Remove unnecessary packages that are not needed
  2. Reduce ambiguity in package.json

Methods to Uninstall NPM Package

This can be perform in the global scope and project scope. Lets looks into them.

Locally Installed Packages

To remove a locally installed package, you must first navigate to the project root folder where node_modules folder and package.json file are located inside.

1. Remove package from node_modules only.

Although the official documentation only mention that it will only remove from node_modules folder, this command will also remove package from `package.json` from my experiments.

npm uninstall <package_name>

2. Remove from dependencies in package.json.

npm uninstall --save <package_name>

# or

npm uninstall -S <package_name>

3. Remove from devDependencies in package.json.

npm uninstall --save-dev <package_name>

# or

npm uninstall -D <package_name>

Globally Installed Packages

To remove a globally installed package, you can be at any folder since the command will always access a stand directory.

Since it is global, there is no concept of dependencies and devDependencies. Just add a `-g` flag to the command to indicate global.

npm uninstall -g <package_name>

# Validating what is in the global
npm list –g

Conclusion

Here, we learn the commands to correctly uninstall NPM package via CLI based on conditions by indicating with a flag in the command.

Show Comments

No Responses Yet

Leave a Reply