{"record":{"id":"a18f3682cac81ab1","repo":"denoland/deno","slug":"err-ipc-sync-fork","errorCode":"ERR_IPC_SYNC_FORK","errorMessage":"IPC cannot be used with synchronous forks","messagePattern":"IPC cannot be used with synchronous forks","errorType":"exception","errorClass":"NodeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/internal/child_process.ts","lineNumber":1144,"sourceCode":"    stdio = [stdio, stdio, stdio];\n  } else if (!ArrayIsArray(stdio)) {\n    throw new ERR_INVALID_ARG_VALUE(\"stdio\", stdio);\n  }\n\n  // Expand stdio array to at least 3 elements (mutates the input array)\n  while (stdio.length < 3) {\n    ArrayPrototypePush(stdio, undefined);\n  }\n\n  // Process each stdio element\n  const result = [];\n\n  for (let i = 0; i < stdio.length; i++) {\n    const value = stdio[i];\n\n    if (value === \"ipc\") {\n      if (sync) {\n        throw new ERR_IPC_SYNC_FORK();\n      }\n      ipc = i;\n      ipcFd = i;\n      ArrayPrototypePush(result, { type: \"ipc\" });\n    } else if (value === \"ignore\" || value === null) {\n      ArrayPrototypePush(result, { type: \"ignore\" });\n    } else if (value === \"pipe\" || value === undefined) {\n      ArrayPrototypePush(result, { type: \"pipe\" });\n    } else if (value === \"inherit\") {\n      ArrayPrototypePush(result, { type: \"inherit\" });\n    } else if (value === \"overlapped\") {\n      ArrayPrototypePush(result, { type: \"overlapped\" });\n    } else if (typeof value === \"number\") {\n      ArrayPrototypePush(result, { type: \"fd\", fd: value });\n    } else if (typeof value === \"string\") {\n      // Invalid string value\n      throw new ERR_INVALID_SYNC_FORK_INPUT(value);\n    } else if (typeof value === \"object\" && value !== null) {","sourceCodeStart":1126,"sourceCodeEnd":1162,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/internal/child_process.ts#L1126-L1162","documentation":"getValidStdio() throws ERR_IPC_SYNC_FORK when a stdio entry equals 'ipc' while the call is on the synchronous path (sync === true, i.e. spawnSync/forkSync internals). An IPC channel needs the parent's event loop to pump messages; a synchronous spawn returns only after the child exits, so Node (and this polyfill) forbid the combination up front.","triggerScenarios":"spawnSync(cmd, args, { stdio: ['ipc', 'pipe', 'pipe'] }); forkSync(script) with an 'ipc' entry; any sync spawn where an 'ipc' stdio element survives normalization.","commonSituations":"Converting async fork() messaging code to spawnSync 'for determinism' in build scripts; copy-pasting a fork stdio preset into a sync call; CLI tools that must block until the child exits but still try to hold a message channel.","solutions":["Remove the 'ipc' entry for synchronous spawns: stdio: ['pipe', 'pipe', 'pipe']","If you need message passing, use the async fork()/spawn() with an event loop","Replace IPC in sync code with stdin/stdout pipes: write input, then read result.stdout"],"exampleFix":"// before\nconst r = spawnSync(process.execPath, [script], { stdio: ['ipc', 'pipe', 'pipe'] });\n\n// after\nconst r = spawnSync(process.execPath, [script], { stdio: ['pipe', 'pipe', 'pipe'], input: JSON.stringify(msg) });\nconst reply = JSON.parse(r.stdout.toString());","handlingStrategy":"validation","validationCode":"if (sync && Array.isArray(stdio) && stdio.includes('ipc')) {\n  throw new Error('IPC is not supported by spawnSync; use async fork()/spawn()');\n}\nconst safeStdio = stdio.map((s) => (s === 'ipc' ? 'pipe' : s));","typeGuard":"const isSyncSafeStdio = (stdio) => !stdio.includes('ipc');","tryCatchPattern":"try { spawnSync(cmd, args, { stdio }); } catch (err) {\n  if (err?.code === 'ERR_IPC_SYNC_FORK') {\n    spawnSync(cmd, args, { stdio: stdio.map((s) => (s === 'ipc' ? 'pipe' : s)) });\n  }\n}","preventionTips":["spawnSync/forkSync can never carry an IPC channel — design sync flows around stdin/stdout","Keep one stdio preset per mode (sync vs async) rather than sharing it","Switch to async fork() as soon as messaging is a requirement"],"tags":["child-process","ipc","stdio","spawn-sync","node-compat","deno"],"backgroundTag":"invalid-stdio-option","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}