denoland/deno · error · TypeError
Passing 'args' in options is not allowed when args are passe
Error message
Passing 'args' in options is not allowed when args are passed as a separate argument
What it means
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.
Source
Thrown at ext/process/40_process.js:834
}
spawn() {
const options = {
__proto__: null,
...(this.#options ?? {}),
stdout: this.#options?.stdout ?? "inherit",
stderr: this.#options?.stderr ?? "inherit",
stdin: this.#options?.stdin ?? "inherit",
};
return spawnChild(this.#command, options);
}
}
function spawn(command, argsOrOptions, maybeOptions) {
if (ArrayIsArray(argsOrOptions)) {
const options = maybeOptions ?? {};
if (options.args !== undefined) {
throw new TypeError(
"Passing 'args' in options is not allowed when args are passed as a separate argument",
);
}
return new Command(command, { ...options, args: argsOrOptions }).spawn();
}
return new Command(command, argsOrOptions).spawn();
}
function spawnAndWait(command, argsOrOptions, maybeOptions) {
if (ArrayIsArray(argsOrOptions)) {
const options = maybeOptions ?? {};
if (options.args !== undefined) {
throw new TypeError(
"Passing 'args' in options is not allowed when args are passed as a separate argument",
);
}
return new Command(command, { ...options, args: argsOrOptions }).output();
}View on GitHub (pinned to 9ad36f7a2c)
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
Example fix
// before
Deno.spawn("git", ["status"], { args: ["status"], stdout: "piped" }); // TypeError
// after
Deno.spawn("git", ["status"], { stdout: "piped" }); Defensive patterns
Strategy: validation
Validate before calling
const { args: _omit, ...optsSansArgs } = options ?? {};
Deno.spawn(cmd, argArray, optsSansArgs); // safe: no duplicate args
// or: Deno.spawn(cmd, { ...options, args: argArray }) Type guard
function hasConflictingArgs(args: unknown, options: { args?: unknown } | undefined): boolean {
return Array.isArray(args) && options?.args !== undefined;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Cannot get 'stdout': 'stdout' is not piped
- Cannot get 'stderr': 'stderr' is not piped
- Illegal constructor
- Piped stdin is not supported for this function, use 'Deno.Co
- ERR_INVALID_ARG_VALUE
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/33379b3e88185184.
Report an issue: GitHub.