almost 2 years ago

The default npm list command not only list the packages installed locally but also the packages they depend on. To most users, showing packages dependency is not necessary, as most of the time, we only want to know what is installed. To fix this, the --depth=0 option can be used:

npm ls --depth=0

So we get the list on the left instead of on the right:

dir_name@1.0.0 /path/blah/blah                 dir_name@1.0.0 /path/blah/blah
|-- babel-core@5.8.3                           |-- babel-core@5.8.3
                                                   |- babel-plugin-constant-folding@1.0.1
                                                   |- babel-plugin-eval@1.0.1

However, this is not enough. Because if you have installed a package either

You are likely to see these errors:

npm ERR! max depth reached: webpack@*, required by babel-loader@5.3.2   // this error is caused by installing webpack globally
npm ERR! extraneous: file-loader@0.8.4 /blah/file-loader   // this error is caused by using npm install instead of npm install --save

To ignore these errors, a solution provided by this blog works:

npm ls --depth=0 "$@" 2>/dev/null

To create a proper shorcut, open your .bash_profile (for Mac):

alias nl="npm ls --depth=0 "$@" 2>/dev/null"
alias nlg="npm ls -g --depth=0 "$@" 2>/dev/null"  #for listing global packages

Reload the .bash_profile file and that's it!

. .bash_profile
← Reference globally installed NPM package Write Javascript in iPython Notebook →
comments powered by Disqus