Is there a way to simply uninstall all unused (undeclared) dependencies from a Node.js project (ones that are no longer defined in my package.json
.) When I update my application I like to have the unreferenced packages removed automatically.
Description. This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed. Extraneous packages are those present in the node_modules folder that are not listed as any package's dependency list.
json. To identify the unused package, just run npx depcheck in the project root directory. Next step is to uninstall the npm packages using npm uninstall command. The post Remove unused npm modules from package.
Note: Recent npm
versions do this automatically when running npm install
if package-locks are enabled, so this is not necessary except for removing development packages with the --production
flag.
Run npm prune
to remove modules not listed in package.json
.
From npm help prune
:
This command removes "extraneous" packages. If a package name is provided, then only packages matching one of the supplied names are removed.
Extraneous packages are packages that are not listed on the parent package's dependencies list.
If the
--production
flag is specified, this command will remove the packages specified in your devDependencies.
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