{"record":{"id":"916d567da24f8c50","repo":"denoland/deno","slug":"err-invalid-arg-type-916d56","errorCode":"ERR_INVALID_ARG_TYPE","errorMessage":"The \"options\" argument must be of type object. Received ${actual}","messagePattern":"The \"options\" argument must be of type object\\. Received (.+?)","errorType":"error_code","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/child_process.ts","lineNumber":332,"sourceCode":"  constructor() {\n    super();\n\n    // 'child_process' channel fires once per ChildProcess construction, before\n    // spawn(). cluster.fork() / cp.fork() / cp.spawn() all flow through here,\n    // so a single publish site covers every entry point.\n    if (childProcessChannel.hasSubscribers) {\n      childProcessChannel.publish({ process: this });\n    }\n  }\n\n  /**\n   * Internal spawn method used by Node.js internals.\n   * This is called after creating a ChildProcess instance.\n   */\n  spawn(options) {\n    // Validate options\n    if (options == null || typeof options !== \"object\") {\n      throw new ERR_INVALID_ARG_TYPE(\"options\", \"object\", options);\n    }\n\n    // Validate envPairs before file (Node.js validation order)\n    const { envPairs } = options;\n    if (envPairs !== undefined && !ArrayIsArray(envPairs)) {\n      throw new ERR_INVALID_ARG_TYPE(\"options.envPairs\", \"Array\", envPairs);\n    }\n\n    // Validate args\n    const { args } = options;\n    if (args !== undefined && !ArrayIsArray(args)) {\n      throw new ERR_INVALID_ARG_TYPE(\"options.args\", \"Array\", args);\n    }\n\n    // Validate file\n    const { file } = options;\n    if (file == null || typeof file !== \"string\") {\n      throw new ERR_INVALID_ARG_TYPE(\"options.file\", \"string\", file);","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/child_process.ts#L314-L350","documentation":"ChildProcess#spawn(options) is the internal spawn entry point in Deno's child_process polyfill, called after a ChildProcess instance is constructed. It requires `options` to be a non-null object; passing null, undefined, a string, or a primitive throws ERR_INVALID_ARG_TYPE before any field is read. User-facing spawn()/fork() build this object for you, so hitting this means the internal method was called directly or an option object was dropped along the way.","triggerScenarios":"Calling child.spawn(null), child.spawn('node'), or a custom spawn wrapper that forwards `undefined` options (e.g. spawn(opts || undefined) where the falsy branch wins).","commonSituations":"Subclassing ChildProcess or re-implementing normalizeSpawnArguments in app code; optional-chaining bugs where options ?? undefined reaches the internal call; porting code from older Node internals with a different spawn signature.","solutions":["Prefer the public spawn(command, args, options) / fork() APIs which construct and validate the options object internally","If using the internal method, always pass a plain object, defaulting to {}","Check `options == null || typeof options !== 'object'` and fail early with your own message"],"exampleFix":"// before\nconst cp = new ChildProcess();\ncp.spawn(maybeOpts); // maybeOpts can be undefined\n\n// after\nconst cp = new ChildProcess();\ncp.spawn(maybeOpts ?? {});","handlingStrategy":"type-guard","validationCode":"if (options == null || typeof options !== 'object' || Array.isArray(options)) {\n  throw new TypeError('spawn options must be a plain object');\n}","typeGuard":"const isSpawnOptions = (o) => o != null && typeof o === 'object' && !Array.isArray(o);","tryCatchPattern":"try { child.spawn(options); } catch (err) {\n  if (err?.code === 'ERR_INVALID_ARG_TYPE' && err.message.includes('\"options\"')) {\n    child.spawn({}); // retry with safe defaults\n  }\n}","preventionTips":["Prefer public spawn()/fork() over the internal ChildProcess#spawn","Default the whole object: spawn(options ?? {})","Destructure with defaults at the wrapper boundary so undefined never travels"],"tags":["child-process","node-compat","deno","argument-validation","internal-api"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T08:17:14.275Z"}