npm ls: listing global packages errors trying to find uninstalled packages

cli
help-wanted
priority:medium
triaged

(Lars Willighagen) #1

What I Wanted to Do

Uninstall @angular/cli, which I installed globally. I did this with:

sudo npm uninstall -g @angular/cli

This worked fine. I then wanted to list global packages.

What Happened Instead

I listed global packages with the command below, which resulted in an error.

$ npm ls -g --depth=0 
/usr/lib
β”œβ”€β”€  error: ENOENT: no such file or directory, open '/usr/lib/node_modules/@angular/cli/package.json
└── npm@6.3.0

npm ERR! error in /usr/lib/node_modules/@angular/cli: ENOENT: no such file or directory, open '/usr/lib/node_modules/@angular/cli/package.json'

Reproduction Steps

  1. sudo npm install -g @angular/cli
  2. sudo npm uninstall -g @angular/cli
  3. npm ls -g --depth=0

Details

When checking out the global node_modules, this folder structure was left:

$ tree /usr/lib/node_modules/@angular/
/usr/lib/node_modules/@angular/
`-- cli
    `-- node_modules

2 directories, 0 files

No log file was specified in the error output.

Platform Info

$ npm --versions
{ npm: '6.2.0',
  ares: '1.14.0',
  cldr: '32.0.1',
  http_parser: '2.8.1',
  icu: '60.2',
  modules: '57',
  napi: '3',
  nghttp2: '1.31.1',
  node: '8.11.2',
  openssl: '1.1.0h',
  tz: '2017c',
  unicode: '10.0',
  uv: '1.22.0',
  v8: '6.2.414.54',
  zlib: '1.2.11' }
$ node -p process.platform
linux

(Kat MarchΓ‘n) #2

Triage Notes: This seems to be one of a series of ongoing issues with npm ls, including npm list globals with depth behaves inconsistently. Also seems like Issue installing angular 5 is connected tot his bug/inspired it?


(Lars Willighagen) #3

Yeah, it β€˜inspired’ it in the sense that I encountered this when cleaning up after trying to help in that thread. I think this is rather a problem with npm uninstall though. Is it expected behavior for that directory structure to stay behind?


(Lars Willighagen) #4

Okay, it seems to be fixed now. I think it had to do with something else: there were two separate global prefixes used (for some reason), namely /usr and /usr/local. Everything was installed in /usr, except npm, which was installed in both but preferred /usr. With some trouble I changed the global prefix and removed npm from /usr/lib and /usr/bin, and now the issue’s gone.