diff --git a/lib/fs.js b/lib/fs.js index ffa216f35388e0..c618bd2cac89cc 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2612,7 +2612,7 @@ realpathSync.native = (path, options) => { options = getOptions(options); path = getValidatedPath(path); const ctx = { path }; - const result = binding.realpath(path, options.encoding, undefined, ctx); + const result = binding.realpath(pathModule.toNamespacedPath(path), options.encoding, undefined, ctx); handleErrorFromBinding(ctx); return result; }; @@ -2772,7 +2772,7 @@ realpath.native = (path, options, callback) => { path = getValidatedPath(path); const req = new FSReqCallback(); req.oncomplete = callback; - return binding.realpath(path, options.encoding, req); + return binding.realpath(pathModule.toNamespacedPath(path), options.encoding, req); }; /** diff --git a/test/parallel/test-fs-long-path.js b/test/parallel/test-fs-long-path.js index 1cb66fa6046152..3f808496ae53f2 100644 --- a/test/parallel/test-fs-long-path.js +++ b/test/parallel/test-fs-long-path.js @@ -43,4 +43,7 @@ console.log({ fs.writeFile(fullPath, 'ok', common.mustSucceed(() => { fs.stat(fullPath, common.mustSucceed()); + + // Tests https://github.com/nodejs/node/issues/39721 + fs.realpath.native(fullPath, common.mustSucceed()); }));