{"record":{"id":"33379b3e88185184","repo":"denoland/deno","slug":"passing-args-in-options-is-not-allowed-when-args","errorCode":null,"errorMessage":"Passing 'args' in options is not allowed when args are passed as a separate argument","messagePattern":"Passing 'args' in options is not allowed when args are passed as a separate argument","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/process/40_process.js","lineNumber":834,"sourceCode":"  }\n\n  spawn() {\n    const options = {\n      __proto__: null,\n      ...(this.#options ?? {}),\n      stdout: this.#options?.stdout ?? \"inherit\",\n      stderr: this.#options?.stderr ?? \"inherit\",\n      stdin: this.#options?.stdin ?? \"inherit\",\n    };\n    return spawnChild(this.#command, options);\n  }\n}\n\nfunction spawn(command, argsOrOptions, maybeOptions) {\n  if (ArrayIsArray(argsOrOptions)) {\n    const options = maybeOptions ?? {};\n    if (options.args !== undefined) {\n      throw new TypeError(\n        \"Passing 'args' in options is not allowed when args are passed as a separate argument\",\n      );\n    }\n    return new Command(command, { ...options, args: argsOrOptions }).spawn();\n  }\n  return new Command(command, argsOrOptions).spawn();\n}\n\nfunction spawnAndWait(command, argsOrOptions, maybeOptions) {\n  if (ArrayIsArray(argsOrOptions)) {\n    const options = maybeOptions ?? {};\n    if (options.args !== undefined) {\n      throw new TypeError(\n        \"Passing 'args' in options is not allowed when args are passed as a separate argument\",\n      );\n    }\n    return new Command(command, { ...options, args: argsOrOptions }).output();\n  }","sourceCodeStart":816,"sourceCodeEnd":852,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/process/40_process.js#L816-L852","documentation":"Deno.spawn(command, argsOrOptions, maybeOptions) (unstable API) detects two conflicting ways to specify arguments: a positional args array plus an args property inside the options object. When both are present it throws a TypeError, because it cannot know which list you intended. Pass args either positionally or in options — never both.","triggerScenarios":"Deno.spawn(\"git\", [\"status\"], { args: [\"log\"], stdout: \"piped\" }) — second argument is an Array and the third (options) also defines args. Also triggered by helpers that merge user options containing args into a call that already passes them positionally.","commonSituations":"Spreading a default options object that already carries args; adapters from Node's child_process.spawn(command, args, options) whose options type includes args; refactors that move args from options to positional without deleting the old property.","solutions":["Delete the args property from the options object when args are passed as the second parameter","Or pass everything in options: Deno.spawn(cmd, { args: [...] }) with no second array","In adapter layers, strip options.args before forwarding when you also forward a positional array"],"exampleFix":"// before\nDeno.spawn(\"git\", [\"status\"], { args: [\"status\"], stdout: \"piped\" }); // TypeError\n\n// after\nDeno.spawn(\"git\", [\"status\"], { stdout: \"piped\" });","handlingStrategy":"validation","validationCode":"const { args: _omit, ...optsSansArgs } = options ?? {};\nDeno.spawn(cmd, argArray, optsSansArgs); // safe: no duplicate args\n// or: Deno.spawn(cmd, { ...options, args: argArray })","typeGuard":"function hasConflictingArgs(args: unknown, options: { args?: unknown } | undefined): boolean {\n  return Array.isArray(args) && options?.args !== undefined;\n}","tryCatchPattern":null,"preventionTips":["Pick one convention per codebase: either positional args or options.args","Strip args when forwarding user options next to your own positional array","In Node adapters, delete options.args before translating to Deno.spawn"],"tags":["deno","spawn","args","options-validation","unstable-api"],"backgroundTag":"duplicate-args-option","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"}