How to uninstall npm packages

There are two ways to uninstall npm packages depending on where you install them:

  • Uninstall local npm packages
  • Uninstall global npm packages

This tutorial will help you to do both.

Uninstalling local npm packages

Local npm packages are packages that you installed as dependencies to a certain JavaScript project. The local npm packages are usually installed in the node_modules/ folder created in your project’s root folder.

To uninstall these local packages, you need to run the npm uninstall command from the terminal.

For example, suppose your project has a dependency on vue package as shown in package.json snippet below:

{
  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^2.6.14",
    "vuex": "^3.6.2"
  },
}

You can uninstall the package with the following command:

npm uninstall vue

Once the vue package has been removed from the node_modules/ folder, the project dependency on the package will also be removed from the package.json file.

When you want to remove multiple packages, you need to specify the package name separated by a space.

The following command removes both vue and vuex packages:

npm uninstall vue vuex

The same process also applies to packages listed as devDependencies and peerDependencies.

Alternatively, you can also start the uninstallation process by removing the package from package.json file and running the npm install command.

From the above package.json example, just remove the packages listed in the dependencies property:

{
  "dependencies": {
    "core-js": "^3.6.5",
  },
}

And then run the npm install command so that the packages will be removed from the node_modules/ folder.

Uninstall global npm packages

You can uninstall global npm packages by adding the -g flag to the npm uninstall command.

For example, suppose you have installed the Vue package globally in the past:

npm install -g vue

You can uninstall the package using the following command:

npm uninstall -g vue

And that’s how you can uninstall both local and global npm packages installed on your computer 😉

Take your skills to the next level ⚡️

I'm sending out an occasional email with the latest tutorials on programming, web development, and statistics. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.