Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically remove dependencies from package.json when using npm uninstall

Tags:

node.js

npm

After npm init I can add dependencies in my package.json using this:

npm install package --save 

And say, I want to uninstall the package and I do so by doing:

npm uninstall package 

but I want my package.json to be updated accordingly too without me having to manually go to the file and delete that line.

From the npm docs it says:

It is strictly additive, so it does not delete options from your package.json without a really good reason to do so.

So, I just wanted to know if this is even possible.

like image 510
shriek Avatar asked Oct 16 '13 23:10

shriek


People also ask

Does npm uninstall remove dependencies?

This uninstalls a package, completely removing everything npm installed on its behalf. It also removes the package from the dependencies , devDependencies , optionalDependencies , and peerDependencies objects in your package. json . Futher, if you have an npm-shrinkwrap.

How do I remove old dependencies from package json?

To remove a package from the dependencies in package. json , use the --save flag. Include the scope if the package is scoped.

How do I uninstall npm global dependencies?

To remove a global package, you need to attach the -g flag to npm uninstall, and then specify the name of the package. The basic syntax for doing this is npm uninstall -g package-name .


1 Answers

Use the same --save flag. If you installed a dependency with:

$> npm install grunt-cli --save 

you can uninstall it, with package.json getting updated, using:

$> npm uninstall grunt-cli --save 

The 'save' flag tells npm to update package.json based on the operation you just made it do.

like image 116
Mike 'Pomax' Kamermans Avatar answered Sep 20 '22 05:09

Mike 'Pomax' Kamermans