node_modules lookup optimization breaks certain project structures #1177

Closed
mafintosh opened this Issue Jun 13, 2011 · 6 comments

Projects

None yet

2 participants

@mafintosh
Node.js Foundation member

There is a problem with the node_modules lookup optimization.
The problem is it breaks the following simple project structure

~/projects/node_modules/    // a general purpose folder for all modules
~/projects/node_modules/general.js
~/projects/foo
~/projects/foo/node_modules/bar.js

now bar.js cannot do require('general'); because of the optimization.

Since the require is mostly being done a program boot time it seems like a bad trade-off to not allow the above structure because of an optimization.

@isaacs

So then, you're proposing that this bit be removed?

Second, if the file calling `require()` is already inside a `node_modules`
hierarchy, then the top-most `node_modules` folder is treated as the
root of the search tree.

I have no problem with that. Wanna try a patch? It should be a pretty simple change to the Module._nodeModulePaths method in lib/module.js. (And the doc change, of course.)

@mafintosh
Node.js Foundation member

Yes - that's exactly what I mean.

I'll try to do the patch.

@mafintosh mafintosh closed this Jun 13, 2011
@mafintosh mafintosh reopened this Jun 13, 2011
@mafintosh
Node.js Foundation member

I've created a patch that fixes the issue. https://gist.github.com/1023916

@isaacs

Awesome. Sorry, I forgot to mention, can you also sign the node CLA? http://nodejs.org/cla.html

Patch looks fine, otherwise :)

@mafintosh
Node.js Foundation member

Great :) I signed the CLA.

@isaacs isaacs added a commit that closed this issue Jun 14, 2011
Mathias Buus Closes #1177 remove one node_modules optimization
to better support certain project structures.
39246f6
@isaacs isaacs closed this in 39246f6 Jun 14, 2011
@isaacs

Landed on 39246f6. Thanks!

@lo1tuma lo1tuma referenced this issue in eslint/eslint Sep 3, 2014
Closed

Potential plugin paths issue #1214

@lo1tuma lo1tuma added a commit to lo1tuma/node that referenced this issue Sep 3, 2014
@lo1tuma lo1tuma doc: fix modules require.resolve documentation
The behavior of the `node_modules` lookup algorithm was
changed in #1177, but the documentation was not updated completely
to describe the new behavior.

The pseudocode of the lookup algorithm also did not metion that
`index.json` is tried to be loaded, if you require a folder.
c2b1643
@lo1tuma lo1tuma added a commit to lo1tuma/node that referenced this issue Sep 3, 2014
@lo1tuma lo1tuma doc: fix modules require.resolve documentation
The behavior of the `node_modules` lookup algorithm was
changed in #1177, but the documentation was not updated completely
to describe the new behavior.

The pseudocode of the lookup algorithm did not metion that
`index.json` is tried to be loaded if you require a folder.
fd7eb9d
@indutny indutny added a commit that referenced this issue Sep 15, 2014
@lo1tuma lo1tuma doc: fix modules require.resolve documentation
The behavior of the `node_modules` lookup algorithm was
changed in #1177, but the documentation was not updated completely
to describe the new behavior.

The pseudocode of the lookup algorithm did not metion that
`index.json` is tried to be loaded if you require a folder.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
7c5fabe
@mscdex mscdex added a commit to mscdex/node that referenced this issue Dec 25, 2014
@lo1tuma lo1tuma doc: fix modules require.resolve documentation
The behavior of the `node_modules` lookup algorithm was
changed in #1177, but the documentation was not updated completely
to describe the new behavior.

The pseudocode of the lookup algorithm did not metion that
`index.json` is tried to be loaded if you require a folder.

Reviewed-By: Fedor Indutny <fedor@indutny.com>
3465a8f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment