{"record":{"id":"4ab7fe63a4ddc3e1","repo":"denoland/deno","slug":"err-worker-path","errorCode":"ERR_WORKER_PATH","errorMessage":"The worker script or module filename must be an absolute path or a relative path starting with './' or '../'.","messagePattern":"The worker script or module filename must be an absolute path or a relative path starting with '\\./' or '\\.\\./'\\.","errorType":"validation","errorClass":"ERR_WORKER_PATH","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/worker_threads.ts","lineNumber":388,"sourceCode":"    }\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, \"../\") &&\n        !StringPrototypeStartsWith(path, \".\\\\\") &&\n        !StringPrototypeStartsWith(path, \"..\\\\\")\n      ) {\n        // On Windows, also allow drive-letter absolute paths (e.g. C:\\...)\n        const isWindowsAbsolute = path.length >= 3 && path[1] === \":\" &&\n          (path[2] === \"\\\\\" || path[2] === \"/\");\n        if (!isWindowsAbsolute) {\n          throw new ERR_WORKER_PATH(specifier);\n        }\n      }\n    }\n","sourceCodeStart":370,"sourceCodeEnd":406,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/worker_threads.ts#L370-L406","documentation":"String specifiers are treated as filesystem paths, never URLs. If the string starts with 'file://', 'data:', 'http://', or 'https://' and options.eval is not set, the polyfill throws ERR_WORKER_PATH — Node's rule that URL semantics require an actual URL object, so URL strings must be wrapped with new URL(...).","triggerScenarios":"new Worker('file:///app/w.js'), new Worker('data:text/javascript,...'), or new Worker('https://example.com/w.js') — a URL-scheme-prefixed string without eval mode.","commonSituations":"String-building specifiers from import.meta.url (which stringifies to a file:// URL); pasting URLs from configs or logs; porting browser worker code that passes URL strings directly.","solutions":["Wrap the string: new Worker(new URL('file:///app/w.js')) or new Worker(new URL('./w.js', import.meta.url)).","For plain local files, drop the scheme and pass '/app/w.js' or './w.js'.","For inline code keep the string but add { eval: true } so it is parsed as source.","Never concatenate import.meta.url as a string; construct a URL object instead."],"exampleFix":"// before\nnew Worker(import.meta.url + '/w.js'); // string is a file:// URL -> ERR_WORKER_PATH\n\n// after\nnew Worker(new URL('./w.js', import.meta.url));","handlingStrategy":"validation","validationCode":"let spec: string | URL = './w.js';\nif (typeof spec === 'string' && /^(file|data|https?):/i.test(spec)) {\n  spec = new URL(spec); // URL strings must become URL objects\n}\nconst w = new Worker(spec);","typeGuard":"const isUrlLikeString = (s: string) => /^(file|data|https?):/i.test(s);","tryCatchPattern":"try { const w = new Worker(spec); } catch (e) { if (e?.code === 'ERR_WORKER_PATH' && typeof spec === 'string' && /^(file|data|https?):/i.test(spec)) { const w2 = new Worker(new URL(spec)); } else throw e; }","preventionTips":["Always construct worker specifiers with new URL('./x', import.meta.url).","Lint for new Worker('...') calls with literal URL-scheme strings.","Reserve string specifiers for filesystem paths; use URL objects for file:/data: URLs."],"tags":["worker-threads","url","path","specifier"],"backgroundTag":"invalid-worker-path","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}