{"record":{"id":"167f94fe573b2152","repo":"denoland/deno","slug":"err-invalid-url-scheme-167f94","errorCode":"ERR_INVALID_URL_SCHEME","errorMessage":"The URL must be one of scheme file or data","messagePattern":"The URL must be one of scheme file or data","errorType":"validation","errorClass":"ERR_INVALID_URL_SCHEME","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/worker_threads.ts","lineNumber":376,"sourceCode":"              hasInvalid = true;\n              break;\n            }\n          }\n        }\n        if (hasInvalid) {\n          throw new ERR_WORKER_INVALID_EXEC_ARGV(\n            [nodeOptions],\n            \"invalid NODE_OPTIONS env variable\",\n          );\n        }\n      }\n    }\n\n    if (typeof specifier === \"object\") {\n      if (\n        !(specifier.protocol === \"data:\" || specifier.protocol === \"file:\")\n      ) {\n        throw new ERR_INVALID_URL_SCHEME([\"file\", \"data\"]);\n      }\n    } else if (typeof specifier === \"string\" && !options?.eval) {\n      // Node.js requires string specifiers to be absolute paths or\n      // relative paths starting with './' or '../'. URLs passed as\n      // strings must be wrapped with `new URL`.\n      if (\n        StringPrototypeStartsWith(specifier, \"file://\") ||\n        StringPrototypeStartsWith(specifier, \"data:\") ||\n        StringPrototypeStartsWith(specifier, \"http://\") ||\n        StringPrototypeStartsWith(specifier, \"https://\")\n      ) {\n        throw new ERR_WORKER_PATH(specifier);\n      }\n      const path = specifier;\n      if (\n        !StringPrototypeStartsWith(path, \"/\") &&\n        !StringPrototypeStartsWith(path, \"./\") &&\n        !StringPrototypeStartsWith(path, \"../\") &&","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/worker_threads.ts#L358-L394","documentation":"The Worker constructor only accepts URL objects whose protocol is file: or data: — worker code must exist on local disk or be inline. Any other scheme (http:, https:, blob:, ...) throws ERR_INVALID_URL_SCHEME with the allowed list ['file', 'data'], matching Node.js, which never fetches worker scripts over the network.","triggerScenarios":"new Worker(new URL('https://example.com/w.mjs')) or new Worker(new URL('blob:...')) — any URL object whose .protocol is not 'file:' or 'data:'.","commonSituations":"Porting browser code that uses URL.createObjectURL(blob) for inline workers; pointing at CDN-hosted worker scripts; config systems that hand out http(s) URLs where a local module path was expected.","solutions":["Fetch the script in the parent, write it to a temp file, and pass a file URL built with pathToFileURL().","Use a data: URL for small inline scripts: new Worker(new URL('data:text/javascript,' + encodeURIComponent(code))).","For local scripts, resolve relative to the module: new Worker(new URL('./w.js', import.meta.url)).","Never attempt http(s) worker specifiers; materialize the code locally first."],"exampleFix":"// before\nconst w = new Worker(new URL('https://cdn.example.com/w.js'));\n\n// after\nimport { pathToFileURL } from 'node:url';\nconst code = await (await fetch('https://cdn.example.com/w.js')).text();\nconst tmp = await Deno.makeTempFile({ suffix: '.js' });\nawait Deno.writeTextFile(tmp, code);\nconst w = new Worker(pathToFileURL(tmp));","handlingStrategy":"type-guard","validationCode":"const spec = new URL(input);\nif (spec.protocol !== 'file:' && spec.protocol !== 'data:') {\n  throw new Error('worker URL must be file: or data:, got ' + spec.protocol);\n}\nconst w = new Worker(spec);","typeGuard":"function isWorkerUrl(u: unknown): u is URL {\n  return u instanceof URL && (u.protocol === 'file:' || u.protocol === 'data:');\n}","tryCatchPattern":"try { const w = new Worker(url); } catch (e) { if (e?.code === 'ERR_INVALID_URL_SCHEME') { /* download/bundle the script locally and switch to a file: URL */ } else throw e; }","preventionTips":["Resolve worker specifiers from import.meta.url so they are always file: URLs.","Keep worker sources in the repo or build output instead of remote URLs.","Assert isWorkerUrl(spec) at worker-creation call sites."],"tags":["worker-threads","url","scheme","node-compat"],"backgroundTag":"invalid-url-scheme","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}