{"record":{"id":"be953c4150aaeee9","repo":"denoland/deno","slug":"the-property-options-eval-must-be-false-when-fi","errorCode":null,"errorMessage":"The property 'options.eval' must be false when 'filename' is not a string.","messagePattern":"The property 'options\\.eval' must be false when 'filename' is not a string\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/worker_threads.ts","lineNumber":493,"sourceCode":"    const serializedWorkerMetadata = serializeJsMessageData({\n      workerData: options?.workerData,\n      environmentData: environmentData,\n      env: env_,\n      argv: argv_,\n      execArgv: options?.execArgv ?? [],\n      name: this.#name,\n      isEval: !!options?.eval,\n      isWorkerThread: true,\n      hasStdin: !!options?.stdin,\n      resourceLimits: resourceLimits_,\n    }, options?.transferList ?? []);\n\n    let sourceCode = \"\";\n    let hasSourceCode = false;\n\n    if (options?.eval) {\n      if (typeof specifier !== \"string\") {\n        throw new TypeError(\n          \"The property 'options.eval' must be false when 'filename' is not a string.\",\n        );\n      }\n      const code = specifier;\n      // Node.js runs eval workers as CJS (sloppy mode).\n      // Pass as source code for execute_script (sloppy mode).\n      // `require` is already available from the Node worker bootstrap.\n      // See: https://github.com/denoland/deno/issues/26739\n      sourceCode = `var __filename = ${\n        // deno-lint-ignore deno-internal/prefer-primordials\n        JSON.stringify(lazyProcess().default.cwd() + \"/[worker eval]\")};\\n` +\n        `var __dirname = ${\n          // deno-lint-ignore deno-internal/prefer-primordials\n          JSON.stringify(lazyProcess().default.cwd())};\\n` +\n        `var module = { exports: {} };\\n` +\n        `var exports = module.exports;\\n` +\n        code;\n      hasSourceCode = true;","sourceCodeStart":475,"sourceCodeEnd":511,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/worker_threads.ts#L475-L511","documentation":"In eval mode the Worker's first argument is the JavaScript source itself, so it must be a string. When options.eval is truthy and the specifier is not a string (usually a URL object), the constructor throws a plain TypeError: The property 'options.eval' must be false when 'filename' is not a string.","triggerScenarios":"new Worker(new URL('./w.js', import.meta.url), { eval: true }) — a URL/path object combined with eval mode; also new Worker(42, { eval: true }).","commonSituations":"Refactoring between file-mode and eval-mode workers and leaving eval: true behind; template code that sets eval from a config flag defaulting to true; passing an already-resolved URL where a code string was expected.","solutions":["For files, drop the flag: new Worker(url) with eval omitted or false.","For inline code, pass source text: new Worker('console.log(1)', { eval: true }).","Derive the flag from the argument type: { eval: typeof source === 'string' && inline }."],"exampleFix":"// before\nnew Worker(new URL('./w.js', import.meta.url), { eval: true });\n\n// after\nnew Worker(new URL('./w.js', import.meta.url));\n// eval mode is for source strings:\nnew Worker(\"console.log('hi')\", { eval: true });","handlingStrategy":"type-guard","validationCode":"if (evalMode && typeof spec !== 'string') {\n  throw new TypeError('eval mode requires the filename argument to be source code (string)');\n}\nconst w = new Worker(spec, evalMode ? { eval: true } : {});","typeGuard":"const canEval = (spec: string | URL): spec is string => typeof spec === 'string';","tryCatchPattern":null,"preventionTips":["Keep one spawnWorker(spec, opts) helper that asserts the eval/specifier pairing.","Never copy eval: true from examples without matching the argument type.","Add a unit test covering both modes of your worker factory."],"tags":["worker-threads","eval","typeerror","arguments"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T06:17:29.519Z"}