Need a solution to remove unused node modules and node modules dependencies from a project.
I have searched internet and found couple of NPM package to do something similar but not exactly my requirement.
Please note, Node modules should be listed/removed if that is neither a dependencies in other node modules nor used in any project code.
Please help
You can use an npm module called depcheck (requires at least version 10 of Node). Install the module: npm install depcheck -g or yarn global add depcheck. Run it and find the unused dependencies: depcheck.
npm-check checks for outdated, incorrect, and unused dependencies. To use npm-check from the command line you have to install it. It requires Node >= 0.11. After installing it, it can be used with typing npm-check in the root project directory, where the package.
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.
Perhaps you could use a tool like 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.
Another one is npm-check
Check for outdated, incorrect, and unused dependencies. ... Kindly informs you if a dependency is not being used in your code ...
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