I tried the following unit tests:
test('nodejs URL pathToFileURL() works', () => {
let dosPath = '\\\\?\\UNC\\diskstation\\home\\cpan-modules.txt'
let theUrl = pathToFileURL(dosPath);
let thePath = fileURLToPath(theUrl);
})
;
And it failed with the following exception:
TypeError [ERR_INVALID_FILE_URL_PATH]: File URL path must be absolute
at getPathFromURLWin32 (internal/url.js:1310:13)
at Object.fileURLToPath (internal/url.js:1342:22)
at Context.<anonymous> (c:\<anonymized>\out\test\suite\extension.test.js:85:29)
at processImmediate (internal/timers.js:439:21)
The file exists and can be read:
Note that the documentation says that pathToFileURL()
will make the path absolute
. This makes the complaint from fileUrlToPath()
about the path not being absolute quite strange.
- https://nodejs.org/api/url.html#url_url_pathtofileurl_path
- https://nodejs.org/api/url.html#url_url_fileurltopath_url
I am developping a VS-Code extension using VS-Code 1.43.1