{"record":{"id":"e0e784fcfe7e0742","repo":"denoland/deno","slug":"err-worker-invalid-exec-argv","errorCode":"ERR_WORKER_INVALID_EXEC_ARGV","errorMessage":"Initiated Worker with invalid execArgv flags: ${invalidFlags}","messagePattern":"Initiated Worker with invalid execArgv flags: (.+?)","errorType":"validation","errorClass":"ERR_WORKER_INVALID_EXEC_ARGV","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/worker_threads.ts","lineNumber":330,"sourceCode":"            continue;\n          }\n          const eqIdx = StringPrototypeIndexOf(flag, \"=\");\n          const flagName = eqIdx === -1\n            ? flag\n            : StringPrototypeSlice(flag, 0, eqIdx);\n          if (workerSilentlyIgnoredFlags.has(flagName)) {\n            continue;\n          }\n          if (!lazyProcess().default.allowedNodeEnvironmentFlags.has(flag)) {\n            invalidFlags[invalidFlags.length] = flag;\n            continue;\n          }\n          if (workerDisallowedFlags.has(flagName)) {\n            invalidFlags[invalidFlags.length] = flag;\n          }\n        }\n        if (invalidFlags.length > 0) {\n          throw new ERR_WORKER_INVALID_EXEC_ARGV(invalidFlags);\n        }\n      }\n    }\n\n    if (options?.env) {\n      const nodeOptions = options.env.NODE_OPTIONS;\n      if (typeof nodeOptions === \"string\" && nodeOptions.length > 0) {\n        // Parse NODE_OPTIONS and validate each flag\n        const parts = StringPrototypeSplit(\n          StringPrototypeTrim(nodeOptions),\n          new SafeRegExp(\"\\\\s+\"),\n        );\n        let hasInvalid = false;\n        for (let i = 0; i < parts.length; i++) {\n          const part = parts[i];\n          if (StringPrototypeStartsWith(part, \"-\")) {\n            const eqIdx = StringPrototypeIndexOf(part, \"=\");\n            const partName = eqIdx === -1","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/worker_threads.ts#L312-L348","documentation":"ERR_WORKER_INVALID_EXEC_ARGV is thrown by the Worker constructor when options.execArgv contains flags that are not recognized Node environment flags, or are valid process-wide flags that are forbidden inside workers because they mutate per-process state. Deno's polyfill checks each leading-'-' token against process.allowedNodeEnvironmentFlags plus a disallowed set (--title, --redirect-warnings, --report-*, tracing/diagnostic flags); V8 profiling flags (--cpu-prof*, --heap-prof*) are accepted and silently ignored.","triggerScenarios":"`new Worker(file, { execArgv: ['--title=main'] })`, `execArgv: ['--max-old-space-size=4096', '--unsupported-flag']`, or flags forwarded from the parent that include worker-forbidden entries; the same validation runs against flags found in options.env.NODE_OPTIONS.","commonSituations":"Forwarding `process.execArgv` into every worker unconditionally; CI or prod harnesses that inject report/tracing flags globally; scripts assuming Deno rejects nothing in execArgv; misconfigured NODE_OPTIONS in the environment.","solutions":["Filter execArgv to flags you know are allowed before constructing the Worker (see validationCode).","Remove worker-forbidden flags from the list: --title, --redirect-warnings, --trace-event-file-pattern, --trace-event-categories, --trace-events-enabled, --diagnostic-dir, --report-signal, --report-filename, --report-dir, --report-directory, --report-compact, --report-on-signal, --report-on-fatalerror, --report-uncaught-exception.","Fix or unset a bad NODE_OPTIONS in the environment (`env | grep NODE_OPTIONS`) when the error comes from options.env rather than execArgv."],"exampleFix":"// before\nnew Worker(filename, { execArgv: process.execArgv }); // may carry --title etc.\n\n// after\nconst workerForbidden = new Set(['--title', '--redirect-warnings', '--diagnostic-dir',\n  '--report-signal', '--report-filename', '--report-dir', '--report-directory',\n  '--report-compact', '--report-on-signal', '--report-on-fatalerror',\n  '--report-uncaught-exception', '--trace-event-file-pattern',\n  '--trace-event-categories', '--trace-events-enabled']);\nconst execArgv = process.execArgv.filter((f) => {\n  const name = f.split('=')[0];\n  return !workerForbidden.has(name) && process.allowedNodeEnvironmentFlags.has(name);\n});\nnew Worker(filename, { execArgv });","handlingStrategy":"validation","validationCode":"const WORKER_FORBIDDEN_FLAGS = new Set([\n  '--title', '--redirect-warnings', '--trace-event-file-pattern',\n  '--trace-event-categories', '--trace-events-enabled', '--diagnostic-dir',\n  '--report-signal', '--report-filename', '--report-dir', '--report-directory',\n  '--report-compact', '--report-on-signal', '--report-on-fatalerror',\n  '--report-uncaught-exception',\n]);\nfunction sanitizeExecArgv(flags: string[]): string[] {\n  return flags.filter((flag) => {\n    if (!flag.startsWith('-')) return true; // flag arguments pass through\n    const name = flag.split('=')[0];\n    if (WORKER_FORBIDDEN_FLAGS.has(name)) return false;\n    return process.allowedNodeEnvironmentFlags.has(name);\n  });\n}\nnew Worker(filename, { execArgv: sanitizeExecArgv(process.execArgv) });","typeGuard":"function isWorkerSafeFlag(flag: string): boolean {\n  if (!flag.startsWith('-')) return true;\n  const name = flag.split('=')[0];\n  if (WORKER_FORBIDDEN_FLAGS.has(name)) return false;\n  return process.allowedNodeEnvironmentFlags.has(flag);\n}","tryCatchPattern":"try {\n  worker = new Worker(filename, { execArgv });\n} catch (err) {\n  if ((err as { code?: string }).code === 'ERR_WORKER_INVALID_EXEC_ARGV') {\n    worker = new Worker(filename, { execArgv: sanitizeExecArgv(execArgv) });\n  } else {\n    throw err;\n  }\n}","preventionTips":["Do not forward process.execArgv into workers blindly; filter it first.","Keep NODE_OPTIONS clean in deploy environments; the same validation applies to options.env.NODE_OPTIONS.","Pass only flags you have verified against process.allowedNodeEnvironmentFlags, minus the report/tracing/title group."],"tags":["worker-threads","node-compat","execargv","cli-flags","node-options"],"backgroundTag":"invalid-cli-flag","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}