Search code examples
node.jsnpmdependenciespackage.json

How to find unused packages in package.json?


Is there a way to determine if you have packages in your package.json file that are no longer needed?

For instance, when trying out a package and later commenting or deleting code, but forgetting to uninstall it, I end up with a couple packages that could be deleted.

What would be an efficient way to determine if a package could safely be deleted?


Solution

  • You can use an npm module called depcheck (requires at least version 10 of Node).

    1. Install the module:

       npm install depcheck -g
      
       or
      
       yarn global add depcheck
      
    2. Run it and find the unused dependencies:

       depcheck
      

    The good thing about this approach is that you don't have to remember the find or grep command.

    To run without installing use npx:

    npx depcheck