NPM: Why is this package installed?

Use npm ls to list installed packages and see the dependency graph of a given package eg:

> npm ls core-js

my_module /path/to/my_module>
└─┬ [email protected]
  └─┬ [email protected]
    └─┬ [email protected]
      └─┬ [email protected]
        └─┬ [email protected]
          └── [email protected]

npm explain <package name> is what you're looking for. It explains why a package is in your node_modules folder by showing a "bottoms up" view. See docs here


As you mention, npm ls shows packages and their dependencies:

> npm ls leveldown
[email protected] C:\Users\mikem\Code\appless
`-- @architect/[email protected]
  `-- [email protected]
    `-- UNMET OPTIONAL DEPENDENCY [email protected]

If npm ls shows it at the top level, and it is not a dependency in the top level package.json, it's likely was previously required and is now no longer used.

Use npm prune to remove the unused package.

Tags:

Node.Js

Npm