{"record":{"id":"8707f26de81d276c","repo":"DIYgod/RSSHub","slug":"fork-is-not-supported-in-cloudflare-workers","errorCode":null,"errorMessage":"fork is not supported in Cloudflare Workers","messagePattern":"fork is not supported in Cloudflare Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-module.ts","lineNumber":90,"sourceCode":"    },\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\nconst eventsModule = Object.assign(events, eventsNamespace);\n\n// Map of module names to their exports","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L72-L108","documentation":"Inline child_process.fork() in lib/shims/node-module.ts throws. fork() spawns a new Node process, which is fundamentally impossible in Workers (no child processes, no Node IPC). It is hard-fail like the other spawn-family members.","triggerScenarios":"A CJS dependency (via createRequire) that calls child_process.fork() to run a child Node script under Workers.","commonSituations":"Worker-pool/cloning patterns ported from Node; task-queue libraries that fork workers.","solutions":["Do not call fork() under Workers — replace with a fetch-based or Durable-Object-based worker model.","Gate the fork path to Node runtime.","Remove the dependency."],"exampleFix":"// before\nrequire('child_process').fork('./worker.js');\n// after\nawait fetch('https://worker-endpoint/do-task');","handlingStrategy":"validation","validationCode":"const isNode = typeof process !== 'undefined' && !!process.versions?.node;\nif (!isNode) {\n  // Workers: replace require('child_process').fork with a fetch/DO model\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').fork('./worker.js');\n  else return fetch(workerEndpoint);\n} catch (e) {\n  if (isWorkersShimError(e)) return fetch(workerEndpoint);\n  throw e;\n}","preventionTips":["Never call fork() under Workers — it implies a child Node process.","Model parallel work via fetch or Durable Objects under Workers.","Reserve fork-based patterns for 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"}