{"record":{"id":"0bf90256daf18219","repo":"DIYgod/RSSHub","slug":"spawn-is-not-supported-in-cloudflare-workers-0bf902","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-module.ts","lineNumber":87,"sourceCode":"    },\n    runInThisContext: () => {\n        throw new Error('vm.runInThisContext is not supported in Workers');\n    },\n    Script: ScriptShim,\n    isContext: () => false,\n    compileFunction: () => {\n        throw new Error('vm.compileFunction is not supported in Workers');\n    },\n};\n\n// Child process shim (inline to avoid import cycle)\nconst child_process = {\n    execSync: (_command: string): Buffer => Buffer.from(''),\n    exec: () => {\n        throw new Error('exec is not supported in Cloudflare Workers');\n    },\n    spawn: () => {\n        throw new Error('spawn is not supported in Cloudflare Workers');\n    },\n    fork: () => {\n        throw new Error('fork is not supported in Cloudflare Workers');\n    },\n    execFile: () => {\n        throw new Error('execFile is not supported in Cloudflare Workers');\n    },\n    execFileSync: () => {\n        throw new Error('execFileSync is not supported in Cloudflare Workers');\n    },\n    spawnSync: () => {\n        throw new Error('spawnSync is not supported in Cloudflare Workers');\n    },\n};\n\n// Create a CJS-compatible events module\n// In CJS, require('events') returns EventEmitter class directly (the default export)\n// but also has named exports attached to it","sourceCodeStart":69,"sourceCodeEnd":105,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L69-L105","documentation":"Inline child_process.spawn() in lib/shims/node-module.ts throws — Workers cannot spawn subprocesses. This is the inlined duplicate of the standalone child-process shim, kept so createRequire's child_process builtin is shape-complete except for the throwing members.","triggerScenarios":"A CJS dependency reached via createRequire that calls child_process.spawn() at runtime under Workers.","commonSituations":"Streaming subprocess wrappers; media tool launchers loaded through a CJS require chain.","solutions":["Prevent the spawn code path under Workers (runtime gate or alternative API).","Use fetch/stream APIs instead of subprocess streaming.","Deploy the route on Node."],"exampleFix":"// before\nrequire('child_process').spawn('ffmpeg', args);\n// after — stream via fetch under Workers\nconst res = await fetch(mediaUrl);","handlingStrategy":"validation","validationCode":"const isNode = typeof process !== 'undefined' && !!process.versions?.node;\nif (!isNode) {\n  // Workers: replace require('child_process').spawn with fetch/stream\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 (isNode) require('child_process').spawn(bin, args);\n  else return streamViaFetch(url);\n} catch (e) {\n  if (isWorkersShimError(e)) return streamViaFetch(url);\n  throw e;\n}","preventionTips":["Block the spawn path in CJS deps under Workers.","Use fetch/ReadableStream instead of subprocess streaming.","Keep subprocess routes on Node."],"tags":["cloudflare-workers","child-process","cjs","shim","runtime"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}