{"record":{"id":"bfe7838027440c42","repo":"denoland/deno","slug":"err-invalid-url-scheme-bfe783","errorCode":"ERR_INVALID_URL_SCHEME","errorMessage":"The URL must be of scheme file","messagePattern":"The URL must be of scheme file","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/url.ts","lineNumber":1378,"sourceCode":" * @see https://www.rfc-editor.org/rfc/rfc3490#section-4\n */\nfunction domainToUnicode(domain: string) {\n  return idnaToUnicode(domain);\n}\n\n/**\n * This function ensures the correct decodings of percent-encoded characters as well as ensuring a cross-platform valid absolute path string.\n * @see Tested in `parallel/test-fileurltopath.js`.\n * @param path The file URL string or URL object to convert to a path.\n * @returns The fully-resolved platform-specific Node.js file path.\n */\nfunction fileURLToPath(path: string | URL): string {\n  if (typeof path === \"string\") path = new URL(path);\n  else if (!ObjectPrototypeIsPrototypeOf(URL.prototype, path)) {\n    throw new ERR_INVALID_ARG_TYPE(\"path\", [\"string\", \"URL\"], path);\n  }\n  if (path.protocol !== \"file:\") {\n    throw new ERR_INVALID_URL_SCHEME(\"file\");\n  }\n  return isWindows ? getPathFromURLWin(path) : getPathFromURLPosix(path);\n}\n\n// https://url.spec.whatwg.org/#percent-decode\nfunction isHexCharByte(byte: number): boolean {\n  // 0-9 A-F a-f\n  return (byte >= 0x30 && byte <= 0x39) || (byte >= 0x41 && byte <= 0x46) ||\n    (byte >= 0x61 && byte <= 0x66);\n}\n\nfunction hexByteToNumber(byte: number): number {\n  return (\n    // 0-9\n    byte >= 0x30 && byte <= 0x39\n      ? (byte - 48)\n      // Convert to uppercase: ((byte & 0xDF) - 65) + 10\n      : ((byte & 0xDF) - 55)","sourceCodeStart":1360,"sourceCodeEnd":1396,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/url.ts#L1360-L1396","documentation":"fileURLToPath() only converts file: URLs — after the type check, any other scheme throws ERR_INVALID_URL_SCHEME ('The URL must be of scheme file'). In Deno this is common: modules imported from https:// have an https import.meta.url, which cannot be mapped to a filesystem path.","triggerScenarios":"`fileURLToPath('https://example.com/mod.ts')`; `fileURLToPath(import.meta.url)` inside a remotely imported module; passing data: or http: URLs.","commonSituations":"Deno scripts importing from the network; code shared between local and remote module execution; build tools that feed bundle or asset URLs into path helpers.","solutions":["Branch on protocol: `if (new URL(u).protocol === 'file:')` convert, else handle remotely","For remote modules, fetch() assets instead of reading the filesystem","Use `import.meta.url.startsWith('file:')` as a cheap pre-check before deriving paths"],"exampleFix":"// before\nconst dir = path.dirname(fileURLToPath(import.meta.url)); // throws for https modules\n\n// after\nconst dir = import.meta.url.startsWith(\"file:\")\n  ? path.dirname(fileURLToPath(import.meta.url))\n  : \".\"; // remote module: fall back to cwd or fetch assets","handlingStrategy":"validation","validationCode":"const u = typeof input === \"string\" ? new URL(input) : input;\nif (u.protocol !== \"file:\") {\n  throw new Error(`expected a file: URL, got ${u.protocol}`);\n}\nreturn fileURLToPath(u);","typeGuard":"const isFileUrl = (v: string | URL): boolean =>\n  (typeof v === \"string\" ? new URL(v) : v).protocol === \"file:\";","tryCatchPattern":"try {\n  p = fileURLToPath(import.meta.url);\n} catch (e: any) {\n  if (e?.code === \"ERR_INVALID_URL_SCHEME\") {\n    p = \".\"; // remote module: no local file, fall back to cwd or fetch\n  } else {\n    throw e;\n  }\n}","preventionTips":["Gate path derivation on import.meta.url.startsWith('file:')","Serve remote-module assets via fetch(), not fs","Centralize protocol checks in one path helper"],"tags":["url","file-url","scheme","deno","node-compat"],"backgroundTag":"invalid-url-scheme","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}