DIYgod/RSSHub · error
exec is not supported in Cloudflare Workers
Error message
exec is not supported in Cloudflare Workers
What it means
Inline child_process.exec() inside lib/shims/node-module.ts throws. This mirrors lib/shims/node-child-process.ts because the createRequire builtin map must expose child_process to CJS callers — but exec itself stays unsupported under Workers. Only execSync is stubbed (returns empty Buffer).
Source
Thrown at lib/shims/node-module.ts:84
},
runInNewContext: () => {
throw new Error('vm.runInNewContext is not supported in Workers');
},
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');
},
};
View on GitHub (pinned to bed535e087)
Solutions
- Ensure the dependency does not reach the exec path under Workers (lazy/guarded).
- Substitute execSync's no-op pattern where a degraded empty result is tolerable.
- Run the consuming route on Node.
Example fix
// before
const cp = require('child_process');
cp.exec('git log -1', cb);
// after
const cp = require('child_process');
const out = cp.execSync('git log -1').toString() || 'unknown'; // shim returns '' Defensive patterns
Strategy: validation
Validate before calling
const isNode = typeof process !== 'undefined' && !!process.versions?.node;
// in CJS-consuming code:
if (isNode) {
require('child_process').exec(cmd, cb);
} else {
// Workers: use execSync stub or fetch
} 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').exec(cmd, cb);
else return '';
} catch (e) {
if (isWorkersShimError(e)) return '';
throw e;
} Prevention
- Audit CJS dependencies reached via createRequire for shell-out calls.
- Prefer execSync (shimmed) over exec where a degraded result is acceptable.
- Deploy shell-using routes on Node.
When it happens
Trigger: A CJS dependency resolved through module.createRequire(...) that calls child_process.exec() at runtime under Workers.
Common situations: A transitive dependency that shells out; bundler-resolved CJS lib probing for git/shell tools.
Related errors
- spawn is not supported in Cloudflare Workers
- fork is not supported in Cloudflare Workers
- execFile is not supported in Cloudflare Workers
- execFileSync is not supported in Cloudflare Workers
- spawnSync is not supported in Cloudflare Workers
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/8a55f017bdbe7f08.
Report an issue: GitHub.