Skip to content

fs.promises.realpath throws ENOENT on long paths on Windows, while the realpathSync version works for the same paths #39721

@radeusgd

Description

@radeusgd

Version

v14.17.3

Platform

Microsoft Windows NT 10.0.18363.0 x64

Subsystem

No response

What steps will reproduce the bug?

Run the following script:

const fs = require("fs");

var path = ".";
for (var i = 0; i < 40; ++i) {
   path += "\\foobar";
   fs.mkdirSync(path);
}

console.log("These two work and yield a valid result:");
console.log(fs.realpathSync(path));
fs.realpath(path, function(err, res) { console.log(err, res); });


console.log("But this one throws ENOENT:");
async function repro() {
   const res = await fs.promises.realpath(path);
   console.log(res);
}

repro();

As described in the code, the first two examples will work correctly, printing the expected results, but the third one (repro) will throw.

How often does it reproduce? Is there a required condition?

It seems to always work, but only on Windows.

What is the expected behavior?

The promise-based variant of realpath should correctly resolve the path, in the same way as the synchronous and callback-based ones.

What do you see instead?

(node:3084) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, realpath '.\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar\foobar'

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions