{"record":{"id":"16c4c8ba093bd2b8","repo":"DIYgod/RSSHub","slug":"spawn-is-not-supported-in-cloudflare-workers","errorCode":null,"errorMessage":"spawn is not supported in Cloudflare Workers","messagePattern":"spawn is not supported in Cloudflare Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-child-process.ts","lineNumber":14,"sourceCode":"// Worker-specific shim for node:child_process\n// This module is not available in Cloudflare Workers\n\nexport function execSync(_command: string): Buffer {\n    // Return empty buffer - git info will fall back to 'unknown'\n    return Buffer.from('');\n}\n\nexport function exec() {\n    throw new Error('exec is not supported in Cloudflare Workers');\n}\n\nexport function spawn() {\n    throw new Error('spawn is not supported in Cloudflare Workers');\n}\n","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-child-process.ts#L1-L16","documentation":"Intentional guard in the Workers shim (lib/shims/node-child-process.ts). spawn() has no Workers equivalent (no subprocess capability), so it throws on call. Like exec(), it is fail-fast; only execSync() is stubbed with an empty-Buffer fallback.","triggerScenarios":"Calling child_process.spawn(...) under the Workers build — typically a long-running subprocess, streaming tool, or a dependency that spawns helpers.","commonSituations":"Puppeteer/Playwright-style process launching; media tool wrappers (ffmpeg); a Node-only utility route deployed to Workers.","solutions":["Do not invoke spawn() in Worker-deployed routes.","Detect the runtime and branch to a Workers-compatible alternative (e.g. fetch-based).","Run that route on the Node target instead of Workers."],"exampleFix":"// before\nimport { spawn } from 'node:child_process';\nconst p = spawn('ffmpeg', ['-i', url]);\n// after — under Workers, fetch the media URL directly instead of spawning ffmpeg\nconst buf = await fetch(url).then((r) => r.arrayBuffer());","handlingStrategy":"validation","validationCode":"function canSpawn(): boolean {\n  return typeof process !== 'undefined' && !!process.versions?.node;\n}\nif (!canSpawn()) {\n  // do not call spawn(); use fetch/stream APIs\n}","typeGuard":"function isWorkersShimError(e: unknown): e is Error {\n  return e instanceof Error && /not supported in Cloudflare Workers/.test(e.message);\n}","tryCatchPattern":"try {\n  if (canSpawn()) spawnTool(args);\n} catch (e) {\n  if (isWorkersShimError(e)) return fallbackStream();\n  throw e;\n}","preventionTips":["Never call spawn() in routes that may run on Workers.","Use fetch()/ReadableStream for I/O instead of subprocess streaming.","Reserve subprocess routes for the Node deployment target."],"tags":["cloudflare-workers","child-process","runtime","shim"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}