You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In other words, node_modules/foo.js takes precedence over node_modules/foo/index.js. I have trouble understanding when this would ever be the desired behavior inside a node_modules/ directory.
Even more awkward, adding a package.json with a main property suddenly turns the precedence around:
The current behavior appears to be at odds with the pseudo-code algorithm from the documentation, that clearly says that foo.js should always be loaded: first LOAD_AS_FILE, and only then LOAD_AS_DIRECTORY.
It seems to be a regression in v0.12. v0.10 always prints '0', v0.12 and newer print either '1' or '0', depending on the value of the main property in package.json.
I guess I'll cook up a PR that restores the v0.10 behavior. I'm not wildly thrilled by the inefficiency of the algorithm but at least it's consistent.
If something as fundamental as module load order is going to be changed after many official releases, then I think it would be a good opportunity to address "#3402: Don't resolve symlinks when requiring" at the same time.
If the regression has existed since 0.12 and there haven't been complaints then that means that the no., of people using the node_modules/foo.js use case is very low. In that case, I would definitely prefer the new consistent behaviour that you propose over the one seen in 0.10.
This is probably fine, since the inconsistency being described assumes that people are modifying node_modules by hand, instead of letting npm do what npm does. It's always a little unsettling to modify the module system though.
Should definitely be consistent. I like the idea of optimizing it... I can't think of anybody using the setup described, where a package and a module exist side-by-side. The fact that we've already "betaed" the new behaviour by accident since 0.12 makes me think it should be proposed for the next major.
Yes, it is, but the question is: do we restore the v0.10 behavior or go with the efficient approach? I think the consensus is that it should be the latter but it wouldn't hurt for @nodejs/ctc to chime in.
They're not quite the same. Issue #5689 is about require('./file') while this one is about require('file') (and also that having a main attribute in package.json changes the load order.)
Activity
bnoordhuis commentedon Jan 8, 2016
The current behavior appears to be at odds with the pseudo-code algorithm from the documentation, that clearly says that foo.js should always be loaded: first
LOAD_AS_FILE, and only thenLOAD_AS_DIRECTORY.It seems to be a regression in v0.12. v0.10 always prints '0', v0.12 and newer print either '1' or '0', depending on the value of the
mainproperty in package.json.I guess I'll cook up a PR that restores the v0.10 behavior. I'm not wildly thrilled by the inefficiency of the algorithm but at least it's consistent.
kzc commentedon Jan 8, 2016
If something as fundamental as module load order is going to be changed after many official releases, then I think it would be a good opportunity to address "#3402: Don't resolve symlinks when requiring" at the same time.
zeusdeux commentedon Jan 9, 2016
If the regression has existed since 0.12 and there haven't been complaints then that means that the no., of people using the
node_modules/foo.jsuse case is very low. In that case, I would definitely prefer the new consistent behaviour that you propose over the one seen in 0.10.cjihrig commentedon Jan 15, 2016
This is probably fine, since the inconsistency being described assumes that people are modifying
node_modulesby hand, instead of letting npm do what npm does. It's always a little unsettling to modify the module system though.sam-github commentedon Jan 18, 2016
Should definitely be consistent. I like the idea of optimizing it... I can't think of anybody using the setup described, where a package and a module exist side-by-side. The fact that we've already "betaed" the new behaviour by accident since 0.12 makes me think it should be proposed for the next major.
jasnell commentedon Mar 22, 2016
@bnoordhuis ... still something you wanna do?
bnoordhuis commentedon Mar 23, 2016
Yes, it is, but the question is: do we restore the v0.10 behavior or go with the efficient approach? I think the consensus is that it should be the latter but it wouldn't hurt for @nodejs/ctc to chime in.
mscdex commentedon Mar 23, 2016
Efficiency! Is what is being proposed here a separate change from say #5689?
bnoordhuis commentedon Mar 23, 2016
They're not quite the same. Issue #5689 is about
require('./file')while this one is aboutrequire('file')(and also that having amainattribute inpackage.jsonchanges the load order.)cjihrig commentedon Mar 23, 2016
+1 to making the change. Should we be using GitHub reactions for this?
mscdex commentedon Mar 23, 2016
-1 to GitHub reactions
jasnell commentedon Mar 23, 2016
I think I'm +1 on this change also.
dlongley commentedon Mar 23, 2016
+1 for the more efficient approach, but also +1 to addressing other important module loading problems at the same time, if possible: #3402
jbergstroem commentedon Mar 23, 2016
I'm
+1to changing the order.SystemParadox commentedon Mar 24, 2016
Oh yes please can we get #3402 fixed as part of this
jasnell commentedon May 30, 2017
@bnoordhuis ... any reason to keep this open?
bnoordhuis commentedon May 30, 2017
I still have this in my backlog but if we decide not to make the change, the documentation would need to be updated.
bnoordhuis commentedon Sep 18, 2017
I don't think I'm going to get around to this so I'll go close it out.