FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

module,win: fix long path resolve by huseyinacacak-janea · Pull Request #53294 · nodejs/node · GitHub

/ node Public

module,win: fix long path resolve - #53294

Merged
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
JaneaSystems:huseyin-11801-long-path-error
Aug 10, 2024
Merged

module,win: fix long path resolve#53294
nodejs-github-bot merged 3 commits into
nodejs:mainfrom
JaneaSystems:huseyin-11801-long-path-error

Conversation

Copy link
Copy Markdown
Contributor

Several issues were encountered with module loading due to extended path lengths on Windows. These have been addressed with corrections implemented across four distinct code locations, accompanied by the addition of a corresponding test case for each to ensure functionality.
Additionally, I've moved es-module/test-GH-50753.js to es-module/test-esm-long-path-win.js as the tests cover more cases than specified in that issue.

Fixes: #50753

nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jun 3, 2024

targos commented Jun 3, 2024

Copy link
Copy Markdown
Member

@nodejs/platform-windows

huseyinacacak-janea force-pushed the huseyin-11801-long-path-error branch from 3ee742c to 27a4505 Compare June 3, 2024 12:11
H4ad previously approved these changes Jun 3, 2024
H4ad dismissed their stale review June 3, 2024 12:53

I actually need more time to take a look, I think the implementation will solve the problem but I want to test in which cases we should include the UNC path, since we didn't do this in all paths in the toNamespacedPath.

H4ad commented Jun 3, 2024

Copy link
Copy Markdown
Member

There are some conditions to include the UNC that you are not following:

node/lib/path.js

Lines 632 to 645 in 58711c2

if (StringPrototypeCharCodeAt(resolvedPath, 0) === CHAR_BACKWARD_SLASH) {
// Possible UNC root
if (StringPrototypeCharCodeAt(resolvedPath, 1) === CHAR_BACKWARD_SLASH) {
const code = StringPrototypeCharCodeAt(resolvedPath, 2);
if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
// Matched non-long UNC root, convert the path to a long UNC path
return `\\\\?\\UNC\\${StringPrototypeSlice(resolvedPath, 2)}`;
}
}
} else if (
isWindowsDeviceRoot(StringPrototypeCharCodeAt(resolvedPath, 0)) &&
StringPrototypeCharCodeAt(resolvedPath, 1) === CHAR_COLON &&
StringPrototypeCharCodeAt(resolvedPath, 2) === CHAR_BACKWARD_SLASH
) {

Although the condition could be matched, I think it would be better to wait for the migration of toNamespacedPath to C++.

Maybe we could include the ToNamespacePath port in this PR, and then leave that other PR just to remove the JS version and rewrite the places they are used.

@anonrig What do you think?

StefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 3, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 3, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59635/

anonrig left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

MoLow commented Jun 3, 2024

Copy link
Copy Markdown
Member

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

in that case, can you convert the blocking "request changes" into a simple suggestion/friendly ask? I don't think this PR should be blocked on a PR that is not being currently worked on

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/59644/

Copy link
Copy Markdown
Contributor Author

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

Sure, no problem, I'll take over your PR and start working on it.

huseyinacacak-janea force-pushed the huseyin-11801-long-path-error branch from 27a4505 to 42b88bf Compare July 1, 2024 09:31
huseyinacacak-janea force-pushed the huseyin-11801-long-path-error branch from 42b88bf to 14a1de0 Compare July 2, 2024 05:37
StefanStojanovic added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 2, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 3, 2024

Copy link
Copy Markdown
Collaborator

CI: https://ci.nodejs.org/job/node-test-pull-request/60050/

Copy link
Copy Markdown
Contributor Author

I prefer to land this after the toNamespacedPath migration to C++. Unfortunately, I don't have the time to pursue this at the moment (afaict, there is only one failing test). I appreciate if you could took over that PR and apply these changes in a follow up PR.

@anonrig I've rebased this PR to use toNamespacedPath. Could you please review it?

Copy link
Copy Markdown
Contributor Author

Is there anything else I can do to help this PR move forward?

H4ad requested a review from anonrig July 15, 2024 12:01
Comment thread src/node_file.cc Outdated
switch (FilePathIsFile(env, file_path)) {
Local<Value> local_file_path =
Buffer::Copy(
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))
env->isolate(), file_path.c_str(), file_path.size())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed. Thanks.

Comment thread src/node_file.cc Outdated
switch (FilePathIsFile(env, file_path)) {
Local<Value> local_file_path =
Buffer::Copy(
env->isolate(), file_path.c_str(), strlen(file_path.c_str()))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Comment thread src/node_modules.cc Outdated
// Check if the path has a trailing slash. If so, add it after
// ToNamespacedPath() as it will be deleted by ToNamespacedPath()
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality
Suggested change
path_value.ToString().back() ==
path_value.ToStringView().ends_with

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Comment thread src/node_modules.cc Outdated
// Check if the path has a trailing slash. If so, add it after
// ToNamespacedPath() as it will be deleted by ToNamespacedPath()
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

ditto

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Comment thread src/node_modules.cc Outdated
bool slashCheck = !path_value.ToString().empty() &&
path_value.ToString().back() ==
std::filesystem::path::preferred_separator;
path_value.ToStringView().ends_with(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

The previous line is not needed path_value.ToString() creates an unnecessary string.

Can you also remove this in other places?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Fixed.

Comment thread src/node_file.cc

Copy link
Copy Markdown
Contributor Author

I've fixed the suggestions. Is there anything else I can do to help this PR move forward?

Copy link
Copy Markdown

@anonrig Is there anything else we can do to help this PR move forward? I'm having many issues with long paths on Windows and am eager to get this fixed.

anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2024
github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 7, 2024

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Collaborator

Copy link
Copy Markdown
Contributor Author

The failing test in the CI is a known flaky test.

Copy link
Copy Markdown
Collaborator

H4ad added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Aug 10, 2024
nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Aug 10, 2024
nodejs-github-bot merged commit 37f9eca into nodejs:main Aug 10, 2024

Copy link
Copy Markdown
Collaborator

Landed in 37f9eca

targos pushed a commit that referenced this pull request Aug 14, 2024
PR-URL: #53294
Fixes: #50753
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
RafaelGSS mentioned this pull request Aug 19, 2024
DanielForniessoria-TomTom added a commit to tomtom-international/tomtom-traffic-analytics-mcp that referenced this pull request Aug 18, 2026
The old comment blamed a Node bug: package.json read silently failing past
MAX_PATH, so `{"type":"module"}` was missed and ESM parsed as CJS. That was
fixed in Node 22.7.0 (nodejs/node#53294, which namespaces fs, ESM resolution
and package.json reads) and this package requires >=22.9.0, so the mechanism
the comment described cannot be why we need the setting.

The reason that does hold up is headroom, measured on this lockfile: the
longest path relative to the repo root is 115 characters hoisted against 190
isolated (at Windows' default virtualStoreDirMaxLength of 60). An ordinary
C:\Users\<first>.<last>\IdeaProjects\tomtom-traffic-analytics-mcp checkout is
63 characters, leaving isolated ~6 before MAX_PATH — a OneDrive-redirected
Documents folder or a worktree subdirectory exceeds it. Enabling long paths
instead needs an admin registry value plus a longPathAware manifest node.exe
does not ship (nodejs/node#40641), which a public repo cannot require.

Also records what the setting does and does not cost, since that was the
review question. It costs strict isolation: an undeclared dependency resolves
locally but breaks in the published bundle. It costs nothing measurable
otherwise — 321 MB and equal install times either way (isolated 4.86/6.65/
5.12s against hoisted 5.82/5.77/5.11s, warm store, frozen lockfile), because
the store dedup comes from packageImportMethod, not from nodeLinker.

Comment only; no behaviour change.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Long node_modules paths cannot be found on Windows when LongPathsEnabled enabled

8 participants


Back | FazBrowse Home | New Git URL