-
Notifications
You must be signed in to change notification settings - Fork 6
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
Doesn't always work with relative paths #1
Comments
Is In what directory is the main script located? Is it also in |
Sorry for the ambiguous example, let me try to state it more clearly: So in the example above, the While I don't think this is a bug, it also wasn't intuitive to me at first as I expected it to work in the same way as |
@kflorence i believe i resolved this one too, can you confirm? |
@tony-o Relative includes are only fixed for modules like "./foo/bar" -- the current solution doesn't work correctly in cases like "../../foo/bar" |
Tried to fix this with: try{
if(required[0] in {".":1}){
let pathToFile = module.parent.filename;
let dirOfCallee = pathToFile.substr(0, pathToFile.lastIndexOf('/'))
required = path.resolve(dirOfCallee, required);
}
return require(required);
} But apparently node modules are cached, which is good, but Hope this helps. Edit: require-new might be useful here. |
I wrote a module that should handle relative paths: https://github.com/fengb/require-optional |
If I'm in
/home/kflorence/dev/project/foo/bar
and I require:optional("../baz/qux")
it will fail because it's trying to look up/home/kflorence/dev/project/baz/qux
instead of/home/kflorence/dev/project/foo/baz/qux
The text was updated successfully, but these errors were encountered: