DIYgod/RSSHub · error
vm.runInThisContext is not supported in Workers
Error message
vm.runInThisContext is not supported in Workers
What it means
vmShim.runInThisContext() in lib/shims/node-module.ts throws. Workers disallow executing code in the current global context; this completes the set of vm execution functions that are import-safe but call-unsafe.
Source
Thrown at lib/shims/node-module.ts:71
}
runInNewContext() {
throw new Error('vm.Script.runInNewContext is not supported in Workers');
}
runInThisContext() {
throw new Error('vm.Script.runInThisContext is not supported in Workers');
}
}
const vmShim = {
createContext: (sandbox?: object) => sandbox || {},
runInContext: () => {
throw new Error('vm.runInContext is not supported in Workers');
},
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: () => {View on GitHub (pinned to bed535e087)
Solutions
- Remove runInThisContext from Worker paths.
- Use bundler-time module resolution instead.
- Run on Node if the behavior is required.
Example fix
// before vm.runInThisContext(code); // after import * as mod from './mod'; // static, build-resolved
Defensive patterns
Strategy: validation
Validate before calling
const vmUsable = typeof process !== 'undefined' && !!process.versions?.node;
if (!vmUsable) {
// skip vm.runInThisContext; use static imports
} Type guard
function isVmShimError(e: unknown): e is Error {
return e instanceof Error && /not supported in Workers/.test(e.message);
} Try / catch
try {
if (vmUsable) vm.runInThisContext(code);
else return importedModule;
} catch (e) {
if (isVmShimError(e)) return importedModule;
throw e;
} Prevention
- Remove runtime self-eval from Worker code paths.
- Resolve modules statically via the bundler.
- Run require-hook style code only on Node.
When it happens
Trigger: Calling vm.runInThisContext(code) under Workers; some require-hook implementations and legacy eval wrappers.
Common situations: Migrated Node loaders; runtime self-modifying code; debugging hooks left enabled.
Related errors
- vm.Script.runInContext is not supported in Workers
- vm.Script.runInNewContext is not supported in Workers
- vm.Script.runInThisContext is not supported in Workers
- vm.runInContext is not supported in Workers
- vm.runInNewContext is not supported in Workers
AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12).
Data as JSON: /api/errors/098406e39e2f74a6.
Report an issue: GitHub.