-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
Require
with a relative path should take into account it comes from a symbolic links
#5481
Comments
have the outer define a prefix variable before requiring them? Or will they both get the modified result... like
something.js otherthing.js I guess no....because LibPath is undefined.... |
Dupe of #3402? The module loader is locked. Introducing a breaking change to it would be a tough sell. |
Actually in #3402 it's clearly said they don't want to change the behavior for relative paths (see especially #3402 (comment)). Which is my issue here. So it's quite different (and likely more difficult).
I understand. I can also totally imagine there is a lot of code that depends on this behavior because the behavior makes sense in a lot of cases as well. So maybe the main issue is the lack of configurability for the resolving mechanism. We can't change the locations where node seaches the dependencies. In my case, I want to run mocha on a directory that's made of symbolic linked files, that are not in the same source directory, but still the target directory's layout is what makes sense in my case, because it's the result of a build step. So for example I'd need to tell node "hey node, this is the root of the requires, please look here if you don't find your requirements elsewhere". But even this would not be quite right. Another way to look at it and that would work in my case, but is less generic because it requires the cooperation of the requiring script. If we keep track of where the parent of a script is (I think we do), we could propose either a specific prefix for the require argument ( |
New PR relevant to this issue here: #5950 |
Thanks, I'll be sure to try this ! |
fyi... because of regressions caused by #5950, a new commit putting it's changes behind a |
Please have a look at this gist for context: https://gist.github.com/julienw/7c31988d43b639dcfde2
Basically we have 2 files in 2 different directories. Yet in one another directory we have 2 links to these 2 files. If file1 has
require('./file2')
it will fail because node's require is looking only in the "real" directory where file1 is. I suggest to augment this behavior to look both in this directory and where the symbolic link is located.I understand it's not very easy to do given the current code as node doesn't keep track that it loaded the file from a symbolic link in the first place. I'd be happy to contribute with some guidance.
The text was updated successfully, but these errors were encountered: