-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
require.resolve with paths and non-existent directory returns incorrect local file when using ./ #18408
Comments
I think the fix for this would be cjihrig@63beb8c. It seems to be a matter of whether or not the provided paths are searched, or if they are just used as a starting point for the resolution. In your example, I think |
If that were the case wouldn't one have to try/catch every directory in the paths array individually if the directories could be missing? Personally I'm using require.resolve in this case to find where an entry point is among multiple possible source directories. I thought that was what require.resolve with the paths option was specifically for since it only returns one file. |
No. An exception is only thrown if no match is found after trying all paths. This is how
|
Oh, excellent. Thank you for the clarification. |
Is this resolved, and a close candidate? |
The behavior remains. I'm not sure if the existing behavior is considered a bug or not. Personally, I think it's a bug. I suppose I could PR cjihrig@63beb8c. |
As explained in here I feel this behavior should be considered a bug. If you try to do Calling If you call Due to this behavior I have to consider paths options unreliable and fallback to using |
I'll open the PR a little bit later today. It will probably have to be a semver major change though. |
@niksajanjic can you try building Node with #23683 and see if that fixes your issue? |
I'll give it a shot next day or 2 and get back to you. |
The paths used by require.resolve() should be treated as starting points for module resolution, and not actually searched. PR-URL: nodejs#23683 Fixes: nodejs#18408 Refs: nodejs#23643 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
The paths used by require.resolve() should be treated as starting points for module resolution, and not actually searched. PR-URL: nodejs#23683 Fixes: nodejs#18408 Refs: nodejs#23643 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Matteo Collina <[email protected]>
Linux 4.9.77 x86_64 GNU/Linux
require.resolve
To replicate create a directory with the following files:
test.js
index.js
exists/index.js
both of the
index.js
files can contain anything. They only have to exist.test.js
should contain the following:Execute the
test.js
file withnode test.js
onv9.3.0
or later.As you can see from the code in the test, simply adding
./
to the file name to be resolved causes a local matching file to be returned.Specifically:
This bug was introduced in
v9.3.0
.v9.2.1
and prior behave correctly.The text was updated successfully, but these errors were encountered: