Find unused npm/yarn packages in node.js

Find unused npm/yarn packages in node.js

Marcell Simon
Marcell Simon

You can check each dependency one by one to see if you use it somewhere in your project, but fortunately, someone already wrote a script for that.

To run without installing the package, use npx:

npx depcheck
WARNING! Some dependencies are listed by this package, even if it's used.

Some packages are not imported directly into your project, so don't delete every package without checking what it's used for. Some false alarms like this have been fixed by them, like webpack and React-related packages, but they still can happen. If you find false alarms, you can create a ticket for them.

If you have a package.json inside a subfolder, it won't check those dependencies, as it's considered another project.

Or you can install the depcheck module globally, and then you can access it anywhere on your machine.

yan global add depcheck


npm install depcheck -g

Then you can run it inside your project's folder to find the unused dependencies: