New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ENOENT error when loading this library #4
Comments
Some info: I can reproduce it in my machine by installing with |
I could reproduce it with without If you install the project with If you install with |
I just published a new version with enhanced detection: https://github.com/sindresorhus/is-installed-globally/releases/tag/v0.3.0 Could you let me know whether it has the same problem? |
Thanks for the quick reply! I'm afraid it's still present. Here's a reproduction:
|
I am having the same issue on macOS and managed to find out why.
Node modules are located for my node installation (pretty recent one) at Here the line where I think the error is: https://github.com/sindresorhus/global-dirs/blob/master/index.js#L46 |
This could be a safer approach for getting the node_modules path: const npmPath = require.resolve("npm");
const nodeModulesDirectoryPath = path.resolve(npmPath, "..", "..", ".."); Happy to patch |
so the strategy of but there are many edge cases and potential configurations. its also really difficult to test said configurations in CI, even if we knew how to arrive at them. I wouldn’t be able to say “yes, send that PR” with any confidence that it wouldn’t break somebody else. maybe an alternative would be providing modules like this one and |
@boneskull It's not supposed to be guessing. It tried to follow what npm/Yarn uses. But yes, it could use some more use of |
We could add it as a last effort, but the existing logic is close to what npm/Yarn uses and should be the preferred, I think. |
using sync APIs will be problematic depending on what’s consuming the module, of course. though perhaps it’s fine to use them unless people are asking about it. but yeah the idea would be to validate each and every assumption. |
it seems like the problem is that homebrew does what homebrew does, and that’s subject to the whims of the project |
@frankdilo Would you be willing to do a PR with your approach as a backup? And maybe also more use of |
@sindresorhus sure thing, will work on it soon |
I don't have much time atm 🏃 to go deep enough but this isn't homebrew's fault. What homebrew does is that it modifies global
...and then if that was really the case we wouldn't have trouble finding global dirs on brewed installations. Bottom line, there is a large portion of config handling (both npm/rc & yarn) that needs to be incorporated into |
I'm not an expert on how I'm currently using this exception as such, and have a fallback to another, less robust, detection method if this happens. |
Btw, no promises made but if you manage to give me some time window to solve it once and for all I'm willing to take a shot this weekend...
ATM, it definitely isn't something impossible to solve you just need to replicate what npm/yarn does without cutting corners (ignoring config files).
FWIW my vote goes against magic paths as temporary/interim/case-by-case solutions. @alcuadrado That being said even if UPDATE: Reason why: nvm-sh/nvm#855 |
That makes sense. This helps me give an explanation to our users. Thanks |
I think perfect may be getting in the way of good here. For a while anyone that installed on a brew version of node super-popular libraries (such as np by @sindresorhus) that relied on A quick patch is in order, we can talk about fixing this for good later on, if that's even possible. |
Calling it good is definitely a stretch although - when you put things in perspective (and I wasn't really aware that this prevents OTOH if inability to run popular/useful tools becomes the final straw forcing someone to move away from installing node with |
I see your point, but this is the first problem I ever had in 3 years of JS development with my brewed installation. |
From what I can tell, this bug is caused by these lines: ... which were introduced in sindresorhus/global-directory#12. Seems to me that the assumption about this path is just wrong, at least with a default setup of Homebrew/Node/npm. |
@sholladay Thanks for pointing this out, PR is out. 👍 |
Hi Sindre,
I've just got a bug report from one of my users that is related to this library. When you require it, it can throw an ENOENT error in this line if
globalDirs.npm.packages
doesn't exist.I'm not sure if this should be considered a bug here or in
global-dirs
.The stack trace of the error:
The text was updated successfully, but these errors were encountered: