In docs of modules:
- If X begins with './' or '/' or '../'
a. LOAD_AS_FILE(Y + X)
b. LOAD_AS_DIRECTORY(Y + X)
But in modules.js, only checked './' or '..'. So, if the module name is leading with '..', It is always used as a relative path
if (request.charCodeAt(0) !== 46/*.*/ &&
(request.charCodeAt(1) !== 46/*.*/ &&
request.charCodeAt(1) !== 47/*/*/)) {
...
}
Maybe no one will name module like this, but may need mention it at docs. : )
This seems fixable to me. Maybe cc @bmeck
Do you think this will be a easy first contribution?
Keep in mind that this part of the code is very performance-sensitive. Any additional checks introduced will incur a penality on every module loaded (usually, this code runs hundreds of times for a application with a few dependencies).
I don't think we need to support corner-cases like ..modulename, given that a package name starting with . is not a valid npm package name.
I agree with @silverwind . How about add a link to name rule of npm or the link @silverwind mentioned above in api docs?
@nodejs/documentation Anything that can be done here to improve the documentation?
ping @nodejs/documentation again . If someone from module is available for mentoring, this can be converted as a good first issue too.
I am not able to reproduce this on Linux. Maybe it's Windows specific? I tried loading files and modules in various ways and they are all loaded properly. No matter if on Node.js 6.x or newer.
Since this issue did not get any traction for a long time and due to the concerns mentioned about supporting this, I'll close the issue. Please feel free to reopen or to leave a comment in case you think this should be opened again.
Most helpful comment
Keep in mind that this part of the code is very performance-sensitive. Any additional checks introduced will incur a penality on every module loaded (usually, this code runs hundreds of times for a application with a few dependencies).
I don't think we need to support corner-cases like
..modulename, given that a package name starting with.is not a valid npm package name.