DIYgod/RSSHub · error
exec is not supported in Cloudflare Workers
Error message
exec is not supported in Cloudflare Workers
What it means
Intentional guard in the Cloudflare Workers shim for node:child_process (lib/shims/node-child-process.ts). The Workers runtime cannot spawn OS processes, so exec() throws immediately when called. Note execSync() is deliberately NOT throwing — it returns an empty Buffer so git-info lookups degrade to 'unknown' instead of crashing.
Source
Thrown at lib/shims/node-child-process.ts:10
// Worker-specific shim for node:child_process
// This module is not available in Cloudflare Workers
export function execSync(_command: string): Buffer {
// Return empty buffer - git info will fall back to 'unknown'
return Buffer.from('');
}
export function exec() {
throw new Error('exec is not supported in Cloudflare Workers');
}
export function spawn() {
throw new Error('spawn is not supported in Cloudflare Workers');
}
View on GitHub (pinned to bed535e087)
Solutions
- Avoid calling exec() in code paths deployed to Workers.
- Gate the call behind a runtime check (Node vs Workers) and skip it under Workers.
- If a degraded value is acceptable, mirror execSync's pattern: return a safe empty default instead of throwing.
- Move the offending route to the Node deployment target.
Example fix
// before
import { exec } from 'node:child_process';
exec('git rev-parse --short HEAD', cb);
// after
import { execSync } from 'node:child_process';
// execSync is shimmed to return '' under Workers
const sha = execSync('git rev-parse --short HEAD').toString().trim() || 'unknown'; Defensive patterns
Strategy: validation
Validate before calling
// detect Workers runtime before any exec() call
const isWorkers =
typeof navigator !== 'undefined' &&
(navigator.userAgent?.includes('Cloudflare-Workers') ||
// @ts-expect-error global only in Workers
typeof caches !== 'undefined' && typeof process === 'undefined');
if (isWorkers) {
// skip exec(); fall back to a static/empty value
} Type guard
function canExec(): boolean {
return typeof process !== 'undefined' && !!process.versions?.node;
} Try / catch
try {
if (canExec()) {
// real exec only on Node
} else {
return ''; // Workers-safe fallback
}
} catch (e) {
if (e instanceof Error && /not supported in Cloudflare Workers/.test(e.message)) return '';
throw e;
} Prevention
- Prefer execSync (shimmed to empty) over exec where a degraded value is fine.
- Audit shell-out calls before deploying a route to Workers.
- Gate subprocess code behind a Node-runtime check.
When it happens
Trigger: Any code path that calls child_process.exec(...) (async shell-out) while running the Cloudflare Workers build of RSSHub — e.g. a route that runs an external binary, or a transitive dependency that probes the shell.
Common situations: A route written for Node that shells out; Puppeteer-style launch wrappers; a library that runs `git`/`hostname` via exec; deploy target switched from Node to Workers without auditing shell usage.
Related errors
- spawn is not supported in Cloudflare Workers
- exec is not supported in Cloudflare Workers
- spawn is not supported in Cloudflare Workers
- fork is not supported in Cloudflare Workers
- execFile is not supported in Cloudflare Workers
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/77d657004c599800.
Report an issue: GitHub.