-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
>=1.6.2 break require('.') with NODE_PATH #1356
Comments
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 |
No, note that it's throw an error only when running node with |
It should not work before io.js 1.6.2 because the commit which added the functionality is only in 1.6.2+ -- 6fc5e95 |
Can you please run the example above @Fishrock123 ? (it also works on node 0.10) |
Works for me as expected: $ cat > index.js
module.exports=1337
$ NODE_PATH=whatever iojs
> require('.')
1337 |
Well it looks like this was another undocumented feature, but it is a regression. Before the change one could do |
On which version are you testing it ? @rlidwka |
This 'feature' looks to be broken by simply setting more than one path in NODE_PATH: On 1.6.1 (with both
Not sure if it's worth to fix, considering it is undocumented and won't work with more than one module dir specified. |
@a8m what is the use-case for the previous behavior? |
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 Also, |
here's a travis example, I hope this demonstrate it well. |
@silverwind PTAL in the example above. |
Shouldn't |
Agree, but patch version should not break the compatibility. and it does. |
@a8m The previous behaviour was probably never intended to work as it did. What if Also, note that |
Agree, but this "feature" works since
I know, but this happens in both situations. |
Well, I doubt this usage is really widespread, but I a fix could be to check if NODE_PATH contains a single entry as well as that entry to contain a module directly in its root. In that case, '.' could resolve to that path. If we do a fix as described above, we should deprecate this usage asap :) |
I'm not a fan of workarounds, especially not when it comes to the module system. I suggest reverting the change and relanding it in v2.x in a few months time if the consensus still is that it's a useful change. |
+1 on reverting and landing in next branch. |
I also vote on a revert, as the module system shouldn't have these sorts of breaking changes. |
Ref: #1185 |
perhaps for 2.0 we should finally put the nail in the |
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 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. |
I agree @monsanto, reverting is my least favourite option here by far |
Thanks @monsanto This is issue in not about the design of For this reason, I'll be +1 on reverting and landing it in |
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. |
I'll think you get me wrong, I'm not fan of this "feature" and not use it actually. |
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? |
@silverwind Doesn't |
@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 |
|
|
Is that really needed? Does your PWD contain another module? It would complicate the fix quite a lot. The search paths used by [/* 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 |
As far as I know, this shouldn't work when
You can play with it yourself (by comparing |
This commit restores the functionality of adding a module's path to NODE_PATH and requiring it with require('.'). As NODE_PATH was never intended to be used as a pointer to a module directory (but instead, to a directory containing directories of modules), this feature is also being deprecated in turn, to be removed at a later point in time. PR-URL: #1363 Fixes: #1356 Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: Rod Vagg <[email protected]>
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. |
Running iojs until
>=v.1.6.1
allow to userequire('.')
(i.e:index.js
) withNODE_PATH
.Using
>=v1.6.2
throw an error.Example:
Could anyone please confirm this regression, so I could work on a fix.
Thx
The text was updated successfully, but these errors were encountered: