Node: Cannot find a module with more than 2 dots prefix, ex require('..my-module')

Created on 16 Oct 2017  路  7Comments  路  Source: nodejs/node

  • Version: v6.1.0+
  • Platform: Windows 7 64-bit
  • Subsystem:

In docs of modules:

  1. 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. : )

doc module

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.

All 7 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

addaleax picture addaleax  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

srl295 picture srl295  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

mcollina picture mcollina  路  3Comments