How to remove npm package from a project?

Posted underJavascript

NPM or Node Package Manager has made it really easy to install and manage packages in JavaScript projects. The number of packages available on npm has been on an increase and it has become very convenient to install a package in a project using npm. However, over time, it becomes important to remove npm package from the project which might be outdated on unused.

Remove npm package from package.json

Removing an npm package from package.json is quite easy and straightforward. You can run the following command to remove or uninstall a package :

npm uninstall <package_name>

For example, let us say we want to remove the bootstrap package from the project. The command would be :

npm uninstall bootstrap

If you installed a package as a devDependency using the --save-dev command, you need to use the --save-dev along with the uninstall command. For example:

npm uninstall --save-dev bootstrap

How to uninstall global npm package?

Uninstalling global npm package is also very similar. To uninstall global npm package you need to run the following command:

npm uninstall -g <package_name>

For example, if you want to uninstall jsHint which say was installed globally, you can run the following command:

npm uninstall -g jshint

Once you run the uninstall command, you can notice that the folder related to the package that you uninstalled would be deleted from the node_modules folder too, and also the reference of the package in the package.json file would be removed.

I hope you have learned how to remove npm package from a project. It is important that we regularly find and remove outdated packages and unused packages from package.json. You can find the outdated and unused packages and use the command to remove these packages to keep your package dependencies in control and to avoid bloating up the build files. Hope you found the article to be helpful. Let us know in the comments.

TaggedNodeJsnpmpackagejs – Read tutorials related to JavaScript, jQuery, HTML5, CSS3 and more !

Cover Image for How to check if checkbox is checked in jQuery?

How to check if checkbox is checked in jQuery?

It is very easy to check if a checkbox is checked in jQuery using the .is() or .prop() method of jQuery combined with the ‘:checked’ selector. There are other ways too like checking for the attribute checked value, however, they aren’t very reliable. The easiest and most stable way to check if checkbox is checked … Read more

Cover Image for [Solved] Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’

[Solved] Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’

You might be facing an “Attempted import error: ‘Switch’ is not exported from ‘react-router-dom’ ” error if you are using the react-router-dom package version 6. This error is caused due to using the older switch syntax of the react-router-dom. From version 6 onwards, the react-router-dom has replaced “Switch” with “Routes”. Let us take a look … Read more