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
Well it looks like this was another undocumented feature, but it is a regression. Before the change one could do NODE_PATH=module iojs -p "require('.')" and get the equivalent of require('./module').
I'm leaning towards that the current behaviour logically more correct, and would consider the old behavior as a bug, because you'd expect that require('.') would get you the module in $PWD and not the module in the first (and only) path in $NODE_PATH.
Also, $NODE_PATH seems not to be intended to actually contain a module in its root, but subdirectories with modules.
I can't understand the calls for revert. This is a super duper edge case, and it was known at the time of applying the require('.') patch that--surprise--the behavior of require('.') was going to subtly change. The churn of the patch, the revert, and applying the patch again dwarfs the trouble of making someone fix their application that they need to fix anyway.
I have no stake in this particular issue, I just don't want to set a precedent for iojs of reverting intentional changes at the drop of a hat. It would be nice to know if I see something cool in the changelog, that I can count on it being available a month later. If you are going to change the behavior, stick to it.
This is issue in not about the design of require, if it's good or bad practice, or how to use it.
It's about regression.
This break people's production code, and it shouldn't.(at least in a patch-version).
For this reason, I'll be +1 on reverting and landing it in v2.0.
This break people's production code, and it shouldn't.(at least in a patch-version).
This is preposterous because this issue scores all three of:
Affects a very small amount of users
Is not an intended feature, might even be a bug
Is trivial to fix for the affected users
Strictest semver would not consider these at all which means every change, no matter what, must increment a major which would obviously make it pointless to use the scheme in the first place.
Therefore in practice when something follows a semver, it doesn't follow it strictly but considers some combination of the factors.
I'll think you get me wrong, I'm not fan of this "feature" and not use it actually.
but some people does(the amount is pointless), and since this "bug" lives outside more than two years, I prefer to catalog it as a "feature".
I have the fix for this almost ready. The only uncertainty is precedence. Should require('.') give the module in PWD or the one in NODE_PATH if both exist?
require('./') is a special case that doesn't use search paths at all. With my fix, require('.') would need to use search paths, and my current approach is to add PWD either in front or in the end of that path array.
Is that really needed? Does your PWD contain another module? It would complicate the fix quite a lot. The search paths used by require are
[/* NODE_PATH paths */,/* node_modules etc. */]
That array is created on startup, and I can't easily discern paths inserted by NODE_PATH from regular paths, and there is the possibilty that NODE_PATH changes during runtime. I'd much prefer just inserting PWD at position 0 if require(.) is used.
Activity
a0viedo commentedon Apr 6, 2015
I can't reproduce this in v1.6.3 nor v1.6.2. With v1.6.1 and v1.6.0 it throws the error
Cannot find module '.'Fishrock123 commentedon Apr 6, 2015
@a8m Are you trying to load a file whose whole name is
.?as of v1.6.2
require('.')works the same asrequire('./').6fc5e95
a8m commentedon Apr 6, 2015
No,
require('.')meansrequire('index'), i.e: directory.note that it's throw an error only when running node with
NODE_PATH, and it works fine in<=1.6.1.(please see the example above)
Fishrock123 commentedon Apr 6, 2015
It should not work before io.js 1.6.2 because the commit which added the functionality is only in 1.6.2+ -- 6fc5e95
a8m commentedon Apr 6, 2015
Can you please run the example above @Fishrock123 ? (it also works on node 0.10)
rlidwka commentedon Apr 6, 2015
require('.')means "require current directory". Same asrequire('./').Works for me as expected:
silverwind commentedon Apr 6, 2015
Well it looks like this was another undocumented feature, but it is a regression. Before the change one could do
NODE_PATH=module iojs -p "require('.')"and get the equivalent ofrequire('./module').a8m commentedon Apr 6, 2015
On which version are you testing it ? @rlidwka
silverwind commentedon Apr 6, 2015
This 'feature' looks to be broken by simply setting more than one path in NODE_PATH:
On 1.6.1 (with both
module1andmodule2being folders in the current dir):Not sure if it's worth to fix, considering it is undocumented and won't work with more than one module dir specified.
Fishrock123 commentedon Apr 6, 2015
@a8m what is the use-case for the previous behavior?
silverwind commentedon Apr 6, 2015
I'm leaning towards that the current behaviour logically more correct, and would consider the old behavior as a bug, because you'd expect that
require('.')would get you the module in$PWDand not the module in the first (and only) path in$NODE_PATH.Also,
$NODE_PATHseems not to be intended to actually contain a module in its root, but subdirectories with modules.13 remaining items
monsanto commentedon Apr 7, 2015
I can't understand the calls for revert. This is a super duper edge case, and it was known at the time of applying the
require('.')patch that--surprise--the behavior ofrequire('.')was going to subtly change. The churn of the patch, the revert, and applying the patch again dwarfs the trouble of making someone fix their application that they need to fix anyway.I have no stake in this particular issue, I just don't want to set a precedent for iojs of reverting intentional changes at the drop of a hat. It would be nice to know if I see something cool in the changelog, that I can count on it being available a month later. If you are going to change the behavior, stick to it.
rvagg commentedon Apr 7, 2015
I agree @monsanto, reverting is my least favourite option here by far
a8m commentedon Apr 7, 2015
Thanks @monsanto
This is issue in not about the design of
require, if it's good or bad practice, or how to use it.It's about regression.
This break people's production code, and it shouldn't.(at least in a patch-version).
For this reason, I'll be +1 on reverting and landing it in
v2.0.petkaantonov commentedon Apr 7, 2015
This is preposterous because this issue scores all three of:
Strictest semver would not consider these at all which means every change, no matter what, must increment a major which would obviously make it pointless to use the scheme in the first place.
Therefore in practice when something follows a semver, it doesn't follow it strictly but considers some combination of the factors.
a8m commentedon Apr 7, 2015
I'll think you get me wrong, I'm not fan of this "feature" and not use it actually.
but some people does(the amount is pointless), and since this "bug" lives outside more than two years, I prefer to catalog it as a "feature".
silverwind commentedon Apr 7, 2015
I have the fix for this almost ready. The only uncertainty is precedence. Should require('.') give the module in PWD or the one in NODE_PATH if both exist?
Fishrock123 commentedon Apr 7, 2015
@silverwind Doesn't
NODE_PATHessentially overwrite what would be the CWD?silverwind commentedon Apr 7, 2015
@Fishrock123 no, the array of search paths is just extended and paths in NODE_PATH are put in front:
https://github.com/iojs/io.js/blob/v1.x/lib/module.js#L474
silverwind commentedon Apr 7, 2015
require('./')is a special case that doesn't use search paths at all. With my fix,require('.')would need to use search paths, and my current approach is to add PWD either in front or in the end of that path array.a8m commentedon Apr 7, 2015
NODE_PATHsilverwind commentedon Apr 7, 2015
Is that really needed? Does your PWD contain another module? It would complicate the fix quite a lot. The search paths used by
requireareThat array is created on startup, and I can't easily discern paths inserted by NODE_PATH from regular paths, and there is the possibilty that NODE_PATH changes during runtime. I'd much prefer just inserting PWD at position 0 if
require(.)is used.a8m commentedon Apr 7, 2015
As far as I know, this shouldn't work when
NODE_PATHchanges during runtime.You can play with it yourself (by comparing
>=1.6.2against<=1.6.1). like so.module: handle NODE_PATH in require('.')
silverwind commentedon Apr 16, 2015
Fixed by 3ad82c3. Note that this usage will print a single deprecation warning on first use, and will be removed in 3.0.0, as it stands now.