Some paths in the module search do not make sens in some case #11657

Open
laurentj opened this Issue Oct 3, 2013 · 1 comment

Comments

Projects
None yet
2 participants
Contributor

laurentj commented Oct 3, 2013

In Module.prototype._getPaths (bootstrap.js, see issue #11339), paths of require.paths are in the list of path where to search the given requested module.

However, when the given requested module id is relative, or when it is an absolute path, it does not make sens to search in the list of require.paths.

for example:

require.path('/usr/local/lib/some_modules/');

and let's imagine that in a module we do

require('/home/me/mymodule');

Then we will have in _paths:

  • /home/me/mymodule because of } else if (fs.isAbsolute(request)) {. This is ok.
  • but also /usr/local/lib/some_modules/home/me/mymodule

This second path should not be there....

Same thing for a relative path:

require('./foo');

We expect that the search will be done only relatively with the path of the current module, not with all path in require.paths.

so the list of require.paths should be added in _paths only in the third case, when the id does not begin with a '.', and when it is not an absolute path.

Collaborator

JamesMGreene commented Oct 4, 2013

As usual, I'll reiterate that the idea was to follow Node's module system setup but I don't believe we applied all of the logic branches, thus resulting in the current weirdness.

Here are Node's rules:
    http://nodejs.org/api/modules.html#modules_all_together

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment