DIYgod/RSSHub · error

fork is not supported in Cloudflare Workers

Error message

fork is not supported in Cloudflare Workers

What it means

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.

Source

Thrown at lib/shims/node-module.ts:90

    },
    Script: ScriptShim,
    isContext: () => false,
    compileFunction: () => {
        throw new Error('vm.compileFunction is not supported in Workers');
    },
};

// Child process shim (inline to avoid import cycle)
const child_process = {
    execSync: (_command: string): Buffer => Buffer.from(''),
    exec: () => {
        throw new Error('exec is not supported in Cloudflare Workers');
    },
    spawn: () => {
        throw new Error('spawn is not supported in Cloudflare Workers');
    },
    fork: () => {
        throw new Error('fork is not supported in Cloudflare Workers');
    },
    execFile: () => {
        throw new Error('execFile is not supported in Cloudflare Workers');
    },
    execFileSync: () => {
        throw new Error('execFileSync is not supported in Cloudflare Workers');
    },
    spawnSync: () => {
        throw new Error('spawnSync is not supported in Cloudflare Workers');
    },
};

// Create a CJS-compatible events module
// In CJS, require('events') returns EventEmitter class directly (the default export)
// but also has named exports attached to it
const eventsModule = Object.assign(events, eventsNamespace);

// Map of module names to their exports

View on GitHub (pinned to bed535e087)

Solutions

  1. Do not call fork() under Workers — replace with a fetch-based or Durable-Object-based worker model.
  2. Gate the fork path to Node runtime.
  3. Remove the dependency.

Example fix

// before
require('child_process').fork('./worker.js');
// after
await fetch('https://worker-endpoint/do-task');
Defensive patterns

Strategy: validation

Validate before calling

const isNode = typeof process !== 'undefined' && !!process.versions?.node;
if (!isNode) {
  // Workers: replace require('child_process').fork with a fetch/DO model
}

Type guard

function isWorkersShimError(e: unknown): e is Error {
  return e instanceof Error && /not supported in Cloudflare Workers/.test(e.message);
}

Try / catch

try {
  if (isNode) require('child_process').fork('./worker.js');
  else return fetch(workerEndpoint);
} catch (e) {
  if (isWorkersShimError(e)) return fetch(workerEndpoint);
  throw e;
}

Prevention

When it happens

Trigger: A CJS dependency (via createRequire) that calls child_process.fork() to run a child Node script under Workers.

Common situations: Worker-pool/cloning patterns ported from Node; task-queue libraries that fork workers.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/8707f26de81d276c. Report an issue: GitHub.