requireg
requireg copied to clipboard
default prefix not resolved when using Brew to install node
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:
- per-project config file (/path/to/my/project/.npmrc)
- per-user config file (~/.npmrc)
- global config file ($PREFIX/etc/npmrc)
- 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.
I will open a PR with the proposed change.
Great! Thank you!
Fixed in: https://github.com/h2non/requireg/pull/6
Closing.
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.
oh! fast reading... I was confused. Re-opening. Thanks!
+1
when node was installed via homebrew. (lib/node_modules) resolver uses process.execPath instead of npm config get prefix.

using npm prefix seems more solid to me.
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.
Yep, running npm config set prefix "/usr/local" fixes it if you installed Node via Homebrew.