Nvm: npm ls -g empty output (npm 3)

Created on 30 Dec 2015  ยท  30Comments  ยท  Source: nvm-sh/nvm

img

alex@alex-Aspire-7741:~/Development/projects/manager$ nvm --version
0.30.1
alex@alex-Aspire-7741:~/Development/projects/manager$ node -v
v5.3.0
alex@alex-Aspire-7741:~/Development/projects/manager$ npm --version
3.3.12

needs followup

All 30 comments

hm, that definitely shouldn't be possible. What's nvm debug print out? What OS are you on?

Ubuntu 16.04 64-bit

alex@alex-Aspire-7741:~$ nvm debug
nvm --version: v0.30.1
$SHELL: /bin/bash
$HOME: /home/alex
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v5.3.0
which node: $NVM_DIR/versions/node/v5.3.0/bin/node
which iojs: 
which npm: $NVM_DIR/versions/node/v5.3.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v5.3.0
npm root -g: $NVM_DIR/versions/node/v5.3.0/lib/node_modules
bash: [: : integer expression expected

(that syntax error at the end is a red herring, fixed in 6094dac1c1a3222d25289a5b26ba83593bdcaa88)

none of that seems wrong. what about cd $(npm root -g) && ls -la?

@ljharb

I've removed all node versions, cleared .npm folder and installed node 5
Everything is normal now

I think the problem was in
nvm reinstall-packages 4 command, but im not sure

Interesting - any idea what global packages you had previously installed on v4?

Something like this, nothing special

โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

i wonder if the np somehow conflicted with npm. I guess I'll close this for now but please follow up if it happens again!

I'm experiencing the same issue.

Using npm v2.14.7, npm ls -g works as expected:

raine[node_modules]$ nvm use 4
Now using node v4.2.1 (npm v2.14.7)

raine[node_modules]$ ls `npm -g prefix`/lib/node_modules
bower/             nodemon/           npm-check-updates@ stylint/
bower-name/        npm/               snyk/

raine[node_modules]$ npm ls -g
/Users/raine/.nvm/versions/node/v4.2.1/lib
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected]
โ”œโ”€โ”€ [email protected] -> /Users/raine/projects/npm-check-updates
โ”œโ”€โ”€ [email protected]
โ””โ”€โ”€ [email protected]

Using npm v3.3.12, npm ls -g prints two empty lines, even though there are clearly modules installed in the global prefix:

raine[node_modules]$ nvm use 5
Now using node v5.1.0 (npm v3.3.12)

raine[node_modules]$ ls `npm -g prefix`/lib/node_modules
bower/                       gulp/                        prefixnote@
browserslist/                gulp-striate@                pulp/
generator-raine-npm-module@  livereload@                  purescript/
generator-refactoru-express/ ngrok/                       striate@
generator-refactoru-html/    node-gyp/                    template20@
generator-yoga@              nodemon/                     yo/
generator-yoga-base@         npm/
generator-yoga-test@         npm-check-updates@

raine[node_modules]$ npm ls -g


raine[node_modules]$ 

@metaraine What does nvm debug and npm root -g print out?

raine[node_modules]$ nvm use 5
Now using node v5.1.0 (npm v3.3.12)

raine[node_modules]$ npm root -g
/Users/raine/.nvm/versions/node/v5.1.0/lib/node_modules

raine[node_modules]$ nvm debug
$SHELL: /bin/bash
$NVM_DIR: '$HOME/.nvm'
$PREFIX: ''
$NPM_CONFIG_PREFIX: ''
nvm current: v5.1.0
which node: $NVM_DIR/versions/node/v5.1.0/bin/node
which iojs: 
which npm: $NVM_DIR/versions/node/v5.1.0/bin/npm
npm config get prefix: $NVM_DIR/versions/node/v5.1.0
npm root -g: $NVM_DIR/versions/node/v5.1.0/lib/node_modules
raine[node_modules]$ 

@metaraine what does npm config list say?

raine[node_modules]$ npm config list
; cli configs
user-agent = "npm/3.3.12 node/v5.1.0 darwin x64"

; userconfig /Users/raine/.npmrc
adepth = "-1"
depth = 0

; node bin location = /Users/raine/.nvm/versions/node/v5.1.0/bin/node
; cwd = /Users/raine/.nvm/versions/node/v5.1.0/lib/node_modules
; HOME = /Users/raine
; "npm config ls -l" to show all defaults.

I'm not familiar with adepth but I wonder if that's the problem - what happens if you comment that line out, and rerun npm ls -g?

No different

that's very strange. same if you comment out depth i assume

yep

:/

at this point, I'd probably uninstall that version of node and reinstall it - there's not much nvm can do about a broken npm :-/

Thanks, a newly installed v5.5/v3.3.12 works. Not sure what was up with the other one.

Phew, glad to hear it. Sometimes turning it off and back on again is the only fix :-)

I'm having the same problem. OS X 10.10.5, Node 5.10.1, npm 3.8.6.

โžœ  ~ node --version
v5.10.1
โžœ  ~ npm --version
3.8.6

โžœ  ~ ls `npm -g prefix`/lib/node_modules
babel                        jsfmt
babelify                     jshint
bower                        nightwatch
[...]

โžœ  ~ npm ls -g


โžœ  ~ npm uninstall -g [TAB]
babel                         jsfmt
babelify                      jshint
bower                         nightwatch
[...]

What's _really_ odd is that if I type npm uninstall -g and then tab for completions, it lists the packages correctly. Ideas?

This seems like it's worth posting an issue on https://github.com/npm/npm itself.

Whoops, my mistake. For reference, looks like the problem was that there was a broken symlink in the global node_modules folder.

So I have this same issue. I noticed that npm ls -g returns nothing. I was running on node 6.1.0.

I just installed node 6.3.0 using nvm install 6.3.0, and then I installed a few global packages and npm ls -g returns nothing. Interestingly though, if I run sudo npm ls -g I get the packages I installed listed. Also interesting, if I nvm use 5.6.0, and then npm ls -g, it shows the global packages properly. So maybe this is just a problem in node versions 6 and above?

@elebetsamer did you use sudo npm install -g to install those modules?

You should never ever use sudo with nvm. nvm is per-user, and using sudo with it will install things in your system nvm - ie, nvm deactivate && npm ls -g will probably print out the modules you tried to install.

@ljharb Nope, I don't use sudo for anything nvm, npm, node related. So I'm not really sure why it seems that the npm ls -g works with sudo but not without.

Here is a screenshot for reference as well.

screen shot 2016-07-14 at 12 27 07 pm

@elebetsamer let's file a new issue for yours. typically empty npm ls -g output means npm is broken, and that doesn't seem to be the case for you.

@ljharb Ok, opened a new issue https://github.com/creationix/nvm/issues/1156

I can confirm what WCPetersen in https://github.com/creationix/nvm/issues/954#issuecomment-207628226 wrote:

The issue was a broken symlink in the global node_modules folder. It was the only broken symlink and removing it instantly resolved it, e.g. npm ls -g showed my installed packages again.

There also is an open issue on the npm project site, see https://github.com/npm/npm/issues/9564, and it seems that it's not officially solved yet.

Was this page helpful?
0 / 5 - 0 ratings