-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
Regression: require.resolve(".", { paths }) behaves differently from require.resolve("./", { paths }) #47000
Comments
pouwerkerk
added a commit
to pouwerkerk/node
that referenced
this issue
Mar 8, 2023
pouwerkerk
added a commit
to pouwerkerk/node
that referenced
this issue
Mar 8, 2023
i just got hit by this today, and when debugging i found the solution the same as the linked PR #47019 is anything missing to fix this? or what needs to be done to move forward with the PR? |
dario-piotrowicz
added a commit
to dario-piotrowicz/node
that referenced
this issue
Jan 23, 2025
dario-piotrowicz
added a commit
to dario-piotrowicz/node
that referenced
this issue
Jan 23, 2025
dario-piotrowicz
added a commit
to dario-piotrowicz/node
that referenced
this issue
Jan 23, 2025
dario-piotrowicz
added a commit
to dario-piotrowicz/node
that referenced
this issue
Jan 24, 2025
…tive Fixes: nodejs#47000 add early return for perf gain fix linting
dario-piotrowicz
added a commit
to dario-piotrowicz/node
that referenced
this issue
Jan 24, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: nodejs#47000
dario-piotrowicz
added a commit
to dario-piotrowicz/node
that referenced
this issue
Jan 24, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: nodejs#47000
aduh95
pushed a commit
that referenced
this issue
Jan 27, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this issue
Jan 30, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
hvanness
pushed a commit
to hvanness/node
that referenced
this issue
Jan 30, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: nodejs#47000 PR-URL: nodejs#56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this issue
Jan 31, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this issue
Feb 4, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
aduh95
pushed a commit
that referenced
this issue
Feb 6, 2025
this change fixes `require.resolve` used with the `paths` option not considering `.` and `..` as relative Fixes: #47000 PR-URL: #56735 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jordan Harband <ljharb@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Version
18.14.2
Platform
22.3.0 Darwin Kernel Version 22.3.0
Subsystem
loader
What steps will reproduce the bug?
This produces:
The same is true of
..
and../
. I leave that as an exercise to the reader. If you rerun the above in node 10, you get the same log for both, as expected:If you want to get more clever, you can put a
index.js
inside of the test directory, and then it'll just give you different results without crashing:How often does it reproduce? Is there a required condition?
Every time.
What is the expected behavior?
The same way it worked in node 10:
What do you see instead?
Different file paths, crash, etc.
Additional information
This seems to be a result of this pull request: #27598
The code in
Module._resolveFilename
only checks for "./" and "../" to determine if the path is a relative path:node/lib/internal/modules/cjs/loader.js
Lines 1027 to 1030 in 3b0c047
Adding === "." and === ".." should fix the problem. Or, given that earlier in the file in
Module._findPath
the same thing is calculated slightly differently:node/lib/internal/modules/cjs/loader.js
Lines 630 to 638 in 3b0c047
Perhaps this should be factored out into a
isRelativePath
function since it seems to be tricky enough to get right to not rely on separate inlined implementations in various different places.The text was updated successfully, but these errors were encountered: