npm list globals with depth behaves inconsistently


(Hannah Wolfe) #1

I am looking at several macbooks, which all use the same bash script to install a development environment including nvm, node, npm, yarn and several global packages as well as much more.

Therefore the machines are very similar, the versions of node, npm, and the global packages are the same and the environments are pretty much the sam. However, npm list with the depth parameter outputs different results on different machines.

What I Wanted to Do

I am using the command: npm list -gs --no-progress --depth=0

I am expecting all top-level installed npm packages to appear with their versions. I am expecting this to output the same packages as ls $(which npm | sed -e 's/bin\/npm$/lib\/node_modules/').

What Happened Instead

Packages that I was expecting to appear are missing from the list. On other machines they are not.

E.g. on machine A the output from npm list with the depth set to 0 was

├── bower@1.8.4
├── depcheck@0.6.9
├── ember-cli@3.1.4
├── eslint@4.19.1
├── fkill-cli@4.1.0
├── ghost-cli@1.8.1
├── grunt-cli@1.2.0
├── gulp@3.9.1
├── knex-migrator@3.1.6
├── npm@5.6.0
├── sqlite3@4.0.2
└── tldr@3.2.2

The output on the same machine, from ls $(which npm | sed -e 's/bin\/npm$/lib\/node_modules/') was: bower, bunyan, depcheck, ember-cli, eslint, fkill-cli, ghost-cli, grunt-cli, gulp, knex, knex-migrator, npm, sqlite3, tldr.

The difference is that bunyan and knex are missing.

On machine B, bunyan is not missing, but knex still is.

We tried different combos of the npm list command:

npm list -g --no-progress --depth=0 - same
npm list -g --no-progress --depth=1 - same
npm list -g now the packages are all present, but as sub dependencies.

Note: knex and bunyan are BOTH subdependencies of knex-migrator.

Reproduction Steps

My best guess was that this was due to the install order.

I tried to make bunyan disappear on the machine B:

  • uninstalling bunyan, knex, and knex-migrator.
  • installing bunyan, then knex-migrator
  • no bug


  • uninstalling bunyan, knex, and knex-migrator.
  • installing knex-migrator, then bunyan
  • no bug

Also tried downgrading to knex-migrator@3.1.6 which was the original version on the machine that didn’t work.

Nothing we tried caused a package to disappear.

Next I tried to get bunyan to appear on machine A:

  • Uninstall and reinstall bunyan
  • Didn’t help


  • Uninstall knex-migrator
  • Bunyan now appears in the list
  • Reinstall knex-migrator
  • Bunyan is still in the list :tada:

Knex-migrator got upgraded during this process.


I wasn’t able to find any permissions differences between the machines.

Platform Info

Machine A:

Aileens-MacBook-Pro / $ npm --versions
{ gscan: '1.5.0',
  npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.11.1',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.50',
  zlib: '1.2.11' }
Aileens-MacBook-Pro  / $ node -p process.platform

Machine B:

Hannahs-MacBook-Pro / $ npm --versions
{ nvm: '0.33.11',
  npm: '5.6.0',
  ares: '1.10.1-DEV',
  cldr: '32.0',
  http_parser: '2.8.0',
  icu: '60.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.11.1',
  openssl: '1.0.2o',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.19.1',
  v8: '6.2.414.50',
  zlib: '1.2.11' }
Hannahs-MacBook-Pro  / $ node -p process.platform

npm ls: listing global packages errors trying to find uninstalled packages
(Kat Marchán) #2

I wonder if something weird is going on with your nvm environment. I notice one machine is using it and the other one isn’t – and nvm definitely moves your global env around.

(Hannah Wolfe) #3

They are both using the exact same setup - both are using nvm 0.33.11, as well as node 8.11.1 and npm 5.6.0.

We both got new macbooks a couple of months apart and used the exact same bash script to do these installations.

Both macbooks are exhibiting “missing” package behaviour, it’s just different packages that are missing - knex AND bunyan on A and just knex on B - neither machine is outputting what I would expect.

(Hannah Wolfe) #4

The command I’m using to compare npm’s results is ls $(which npm | sed -e 's/bin\/npm$/lib\/node_modules/') and the output of which npm for machine A is /Users/aileen/.nvm/versions/node/v8.11.1/lib and for machine B it is /Users/hannah/.nvm/versions/node/v8.11.1/lib

(Kat Marchán) #5

I’m basing my assumption on these bits:

So I guess that’s a red herring. Sorry about that :sweat_smile:

Thanks for the report. npm ls does seem to be acting funny. We’ll take a look when we’re able but if anyone’s interested in eyeballing the situation and helping out, that would also be :100:. I’m hard-pressed to speculate about why this might be happening, but @iarna knows these bits better than me :slight_smile:

(Hannah Wolfe) #6

I groked the code but I don’t think this is the kind of thing you can drop into of an afternoon with no prior experience :smiley:

(Kat Marchán) #7

yeah, I’m not so sure either :sweat_smile: probably a good learning experience for someone with more free time who wants to learn how that bit of the CLI works hah

(Rebecca Turner) #8

I have… no better guesses. This one is very weird.(npm ls is kind of weird itself, its overdue for a rewrite.)