$ node -v
v12.18.4
$ cd /tmp
$ node -e "console.log(fs.realpathSync(''))"
/tmp
$ node -e "fs.realpath.native('', (e) => void console.log(e))"
[Error: ENOENT: no such file or directory, realpath ''] {
errno: -2,
code: 'ENOENT',
syscall: 'realpath',
path: ''
}
For more context:
fs.promises.realpath('') returns a rejection with ENOENT.fs.realpath('', (...args) => console.log(args)) passes null, CWD to the callback.fs.realpathSync('') returns CWD.That output kind of makes sense, knowing what I know about how fs.realpath() is implemented, but it behaves differently on Windows so we should make a judgment call on what we think is the appropriate behavior.
fs.promises.realpath('')returns a rejection with ENOENT.
That's because it's a wrapper around fs.realpath.native rather than fs.realpath. No idea why.
here is some more on this:
> fs.realpath(Buffer.from([]), (e, p) => console.log([e && e.path, p]))
undefined
> [ null, '/tmp' ]
> fs.realpath.native(Buffer.from([]), (e, p) => console.log([e && e.path, p]))
undefined
> [ '', undefined ]
> fs.realpath(Buffer.from([1]), (e, p) => console.log([e && e.path, p]))
undefined
> [ '/tmp/\u0001', undefined ]
> fs.realpath.native(Buffer.from([1]), (e, p) => console.log([e && e.path, p]))
undefined
> [ '\u0001', undefined ]
Most helpful comment
That output kind of makes sense, knowing what I know about how
fs.realpath()is implemented, but it behaves differently on Windows so we should make a judgment call on what we think is the appropriate behavior.That's because it's a wrapper around
fs.realpath.nativerather thanfs.realpath. No idea why.