DIYgod/RSSHub · error

spawn is not supported in Cloudflare Workers

Error message

spawn is not supported in Cloudflare Workers

What it means

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.

Solutions

  1. Prevent the spawn code path under Workers (runtime gate or alternative API).
  2. Use fetch/stream APIs instead of subprocess streaming.
  3. Deploy the route on Node.

Example fix

// before
require('child_process').spawn('ffmpeg', args);
// after — stream via fetch under Workers
const res = await fetch(mediaUrl);
Defensive patterns

Strategy: validation

Validate before calling

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

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').spawn(bin, args);
  else return streamViaFetch(url);
} catch (e) {
  if (isWorkersShimError(e)) return streamViaFetch(url);
  throw e;
}

Prevention

When it happens

Trigger: A CJS dependency reached via createRequire that calls child_process.spawn() at runtime under Workers.

Common situations: Streaming subprocess wrappers; media tool launchers loaded through a CJS require chain.

Related errors


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

Appendix: source

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

    },
    runInThisContext: () => {
        throw new Error('vm.runInThisContext is not supported in Workers');
    },
    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

View on GitHub (pinned to bed535e087)