Marcel Panse
Marcel Panse

Reputation: 642

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?

Upvotes: 25

Views: 42723

Answers (3)

AbdelghanyMh
AbdelghanyMh

Reputation: 419

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

Upvotes: 21

袁文涛
袁文涛

Reputation: 856

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

Upvotes: 7

Saurabh Singh
Saurabh Singh

Reputation: 217

you can use npm-check for finding outdated, incorrect, and unused dependencies in your project. After installing it you have to only run npm-check command in your terminal and it will list you status of your dependencies in your project

Upvotes: 8

Related Questions