{"record":{"id":"cfdf15a691d0686a","repo":"denoland/deno","slug":"err-invalid-arg-type-cfdf15","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"arguments[${pos}]\" argument must be of type object. Received ${actual}","messagePattern":"The \"arguments\\[(.+?)\\]\" argument must be of type object\\. Received (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/child_process.ts","lineNumber":127,"sourceCode":"  let execArgv;\n  let options: SpawnOptions & {\n    execArgv?: string;\n    execPath?: string;\n    silent?: boolean;\n  } = { __proto__: null } as typeof options;\n  let args: string[] = [];\n  let pos = 1;\n  if (pos < arguments.length && ArrayIsArray(arguments[pos])) {\n    args = arguments[pos++];\n  }\n\n  if (pos < arguments.length && arguments[pos] == null) {\n    pos++;\n  }\n\n  if (pos < arguments.length && arguments[pos] != null) {\n    if (typeof arguments[pos] !== \"object\" || ArrayIsArray(arguments[pos])) {\n      throw new ERR_INVALID_ARG_TYPE(\n        `arguments[${pos}]`,\n        \"object\",\n        arguments[pos],\n      );\n    }\n\n    options = { __proto__: null, ...arguments[pos++] } as typeof options;\n  }\n\n  // Validate null bytes in args\n  for (let i = 0; i < args.length; i++) {\n    if (typeof args[i] === \"string\") {\n      validateNullByteNotInArg(args[i], `args[${i}]`);\n    }\n  }\n\n  // Validate null bytes in execPath\n  if (options.execPath != null) {","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/denoland/deno/blob/89f33cbef296a2b287f323d42de54c871fa69c77/ext/node/polyfills/child_process.ts#L109-L145","documentation":"normalizeSpawnArguments implements the overloads spawn/execFile/fork(command[, args][, options]): after consuming an optional args array and skipping null, the next positional argument must be a plain options object. The most common trigger is passing args as a bare string (e.g. spawn('ls', '-la')), which lands in the options slot and fails the object check.","triggerScenarios":"spawn('ls', '-la'); spawn('node', 'script.js'); spawn('cmd', ['-a'], 'inherit'); execFile('bin', '--flag'); fork('child.js', '--arg') where a string occupies the arguments[pos] slot.","commonSituations":"Coming from exec() which accepts a single command string; passing shell-style flag strings; forgetting the array brackets around args; passing an array as options.","solutions":["Wrap the arguments in an array: spawn('ls', ['-la'])","Pass options as an object: spawn('cmd', ['-a'], { stdio: 'inherit' })","Use exec() when you genuinely want a full shell command string"],"exampleFix":"// before\nspawn('ls', '-la');\n// after\nspawn('ls', ['-la']);","handlingStrategy":"validation","validationCode":"const args = Array.isArray(rest) ? rest : [];\nconst opts = typeof last === 'object' && last !== null && !Array.isArray(last) ? last : {};\nspawn(cmd, args, opts);","typeGuard":"const isSpawnArgs = (a) => a == null || Array.isArray(a);\nconst isSpawnOptions = (o) => o == null || (typeof o === 'object' && !Array.isArray(o));","tryCatchPattern":null,"preventionTips":["Always pass args as an array, options as an object","Use exec() for whole shell command strings","Type the wrapper parameters explicitly (string, string[], object)"],"tags":["child-process","spawn","validation","node-compat"],"backgroundTag":null,"analyzedSha":"89f33cbef296a2b287f323d42de54c871fa69c77","analyzedAt":"2026-08-16T07:54:21.310Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}