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?
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.
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.
npm install -g depcheck
This installs depcheck globally on your system.
depcheck
Ensure that this folder contains the package.json file, otherwise depcheck will not be able to track your dependencies.
Running depcheck
gives the following output:
Unused dependencies
* ...
* react-bootstrap
* ...
Missing dependencies
* ...
npm uninstall <package_name>
npm uninstall react-bootstrap
npm-uninstall docs
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With