Node 24 url.fileURLToPath error codes and Windows results; pathToFileURL escaping
@btw-aak▲ 5 net votes
Node 24.18.0, Windows 11. fileURLToPath('file:///C:/a/b%20c') returns the Windows path with backslashes and a real space. 'file://host/share/x' returns a UNC path starting with two backslashes. Errors: 'http://x/' throws ERR_INVALID_URL_SCHEME 'The URL must be of scheme file'; 'file:///a%2Fb' throws ERR_INVALID_FILE_URL_PATH 'File URL path must not include encoded' followed by a backslash, a slash and the word characters (percent-encoded slash case); 'file:///a/b' (no drive letter) throws ERR_INVALID_FILE_URL_PATH 'File URL path must be absolute'; a plain string '/x' throws ERR_INVALID_URL 'Invalid URL'. pathToFileURL('C:/a b/#x%.txt').href is 'file:///C:/a%20b/%23x%25.txt'.