jonschlinkert / global-prefix

Get the npm global path prefix. Same code used internally by npm.
MIT License
28 stars 12 forks source link

Returning incorrect prefix #3

Closed paulirish closed 8 years ago

paulirish commented 8 years ago

Here's what global-prefix returns:

/Users/paulirish/.homebrew/Cellar/node/5.4.1

Here's where they actually are:

/Users/paulirish/.homebrew/    # …lib/node_modules/

cc @tunnckoCore

jonschlinkert commented 8 years ago

thanks for the issue, I'm looking into it now. (sorry @tunnckoCore and @paulirish looks like I was wrong on #2 and this might have been avoided)

While I'm looking for a fix, here is the code used by npm for the default global prefix.

jonschlinkert commented 8 years ago

also to clarify, @tunnckoCore / @paulirish, this issue would be resolved by using the custom prefix defined in npmrc, correct?

tunnckoCore commented 8 years ago

Actually i made a workaround. Initially I thought this export $NODE_PATH=$(npm config get prefix) would work, and have logic to work, but it didn't. So I mv node executable from /usr/bin/node to /usr/local/bin/node, and i was partially surprised that it did not break anything. But in some case it may need also to create symbolic link from /usr/local/bin/node to /usr/bin/node (i'm not sure).

But yea.. haha, we always can do tricks, but it's not a good thing. :D

correct?

yes

xapou commented 8 years ago

Same issue for me. Installed node via homebrew without npm and then npm.

var prefix = require('global-prefix');
console.log(prefix);

==> /usr/local

but the correct path given by npm prefix -g is:

npm prefix -g

==> /Users/xp/.node

I noticed this bug when calling npm-check -g which depends on global-modules See discussion here

jonschlinkert commented 8 years ago

@xapou, @tunnckoCore, @paulirish. Sorry for the delay, but the reason I haven't pushed up a fix for this is that I haven't found a satisfactory solution to the issue.

To confirm, are (were) you all using nvm when the error occurred? I believe @tunnckoCore mentioned he was (correct?), and since comments from both @paulirish and @xapou mention homebrew, I'm wondering if this is related to https://github.com/creationix/nvm/issues/855.

cc @dylang

paulirish commented 8 years ago

wasn't using nvm.

i have node installed through homebrew and I have homebrew configured to install inside of ~/.homebrew instead of /usr/local which is non-default, but fairly common.

tunnckoCore commented 8 years ago

wasn't using nvm.

same here. I started using nvm (and currently using), because of these bugs. Node was installed through pacman (archlinux package manager) which install inside /usr - that's okey. And I set npm prefix to be /usr/local to be able to use cli apps without sudo, including npm.

xapou commented 8 years ago

I wasn't using nvm either.