In this quick tutorial, I'll tell you how you can find the unused npm modules in your project and remove them.
Go to the project's root folder and run the below command,
npx depcheck
It will display all the unused packages in your project.
To uninstall a module simply run the below command
npm uninstall <package>
or
yarn remove <package>
Top comments (5)
so i created this script to remove ALL UNUSED deps, (works in unix):
#!/bin/bash
file='unused-deps.txt'
echo "list all unused deps"
npx depcheck > $file
n=1
while read line; do
dep=$( echo "$line" | cut -c 3- )
echo "uninstall : $dep"
npm uninstall "$dep"
n=$((n+1))
done < $file
bash removeUnusedDeps.sh
in your terminalnice idea !
I love you!
Uninstall all of the unused deps:
Note: You may want to run
npx depcheck
again right after, as you may have removed something that you didn't use, but it may have had a dependency that you did use.Hi.
Do you know how to get the list of all the unused modules and uninstall them automatically?
Thank you.