requireg icon indicating copy to clipboard operation
requireg copied to clipboard

default prefix not resolved when using Brew to install node

Open mhofman opened this issue 9 years ago • 8 comments

When node is installed using brew, the process.execPath isn't /usr/local/bin/node, which causes the default prefix to be invalidly resolved.

According to the npm config documentation, the config is resolved from the following places:

  1. per-project config file (/path/to/my/project/.npmrc)
  2. per-user config file (~/.npmrc)
  3. global config file ($PREFIX/etc/npmrc)
  4. npm builtin config file (/path/to/npm/npmrc)

The problem is that 3) & 4) are not possible to figure out without resolving the location of npm. The rc package will only find the configs in 1), 2) and sometimes 3) depending on the prefix. In particular 4) caused issue #4 on Windows, which was solved by hard coding the content of the npm builtin prefix config.

Unless someone has a better suggestion, I suggest that we hard code the default prefix location on all platforms, similar to Windows. This shouldn't have an impact since after #6, the resolve process first tries using prefix and then using the process.execPath anyway, which means that even if we hardcode the wrong default prefix, the execPath based resolution will still happen as it currently does.

mhofman avatar Sep 27 '16 18:09 mhofman

I will open a PR with the proposed change.

mhofman avatar Sep 27 '16 18:09 mhofman

Great! Thank you!

h2non avatar Sep 27 '16 18:09 h2non

Fixed in: https://github.com/h2non/requireg/pull/6

Closing.

h2non avatar Oct 25 '16 10:10 h2non

Actually this wasn't fixed by #6 . I still need to create a PR. I started work on this but had to switch priorities and forgot about this.

mhofman avatar Oct 25 '16 17:10 mhofman

oh! fast reading... I was confused. Re-opening. Thanks!

h2non avatar Oct 25 '16 20:10 h2non

+1 when node was installed via homebrew. (lib/node_modules) resolver uses process.execPath instead of npm config get prefix. image

using npm prefix seems more solid to me.

pwang2 avatar Nov 02 '16 15:11 pwang2

it seems the issue is rc('npm').prefix here. If the prefix is not explicitly set in npmrc. the builtin prefix will not be picked up. manual set in ~/.npmrc will fix.

pwang2 avatar Nov 02 '16 15:11 pwang2

Yep, running npm config set prefix "/usr/local" fixes it if you installed Node via Homebrew.

stevenzeck avatar Jul 03 '18 15:07 stevenzeck