Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove unused dependencies in React

How do I detect unused dependencies in a React project? I know there are npm packages that can do it, but they only work with normal js projects, not with Reacts jsx file. Is there a similar package that works with React?

like image 767
Marcel Panse Avatar asked Jul 29 '15 07:07

Marcel Panse


People also ask

How do I remove unused npm dependencies?

You can use npm-prune to remove extraneous packages. Extraneous packages are packages that are not listed on the parent package's dependencies list. If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.

How do I delete dependencies?

To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located. I will be using Nodemon to demonstrate how to remove a dev dependency.


2 Answers

Using depcheck to Track Dependencies

npm install -g depcheck

This installs depcheck globally on your system.

Run the following command inside your folder where you want your dependencies to be checked.

depcheck

Ensure that this folder contains the package.json file, otherwise depcheck will not be able to track your dependencies.

Let suppose you installed the react-bootstrap package and did not import anything from it.

Running depcheck gives the following output:

Unused dependencies
* ...
* react-bootstrap
* ... 
Missing dependencies
* ...  

In general, you can uninstall any npm package or dependency by running the following command:

npm uninstall <package_name>
npm uninstall react-bootstrap

npm-uninstall docs

like image 157
AbdelghanyMh Avatar answered Oct 20 '22 04:10

AbdelghanyMh


try about depcheck,Depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are missing from package.json.

NOTE: Depcheck requires installed node version > NODE 10

like image 6
袁文涛 Avatar answered Oct 20 '22 03:10

袁文涛