Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NPM: Why is this package installed?

Tags:

node.js

npm

How do I determine why a particular package is installed? In other words, what package(s) depend on this package?

The package in question is babelify. npm ls shows it at the top level, but it is not included in package.json anywhere.

like image 430
Olivia Witt Avatar asked Mar 17 '16 00:03

Olivia Witt


People also ask

How do you check if an npm package is installed?

Run the npm list command in your terminal to see what local packages and their dependencies you have installed. Use the npm list command and package name to see whether a package is installed locally or not.

How do I see which npm packages are installed globally?

To check for all globally installed packages and its dependencies, run the npm list command followed by the -g flag. This above command prints the all globally installed packages in tree view. You can also check if a specific package is installed globally or not using the npm list -g followed by package name.

Where does npm get packages from?

Local Installation of Packages: Local packages are installed in the directory where you run npm install <package-name> and they are put in the node_modules folder under this directory.


2 Answers

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] 
like image 156
Khaled Awad Avatar answered Oct 04 '22 05:10

Khaled Awad


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.

like image 44
mikemaccana Avatar answered Oct 04 '22 06:10

mikemaccana