{"record":{"id":"098406e39e2f74a6","repo":"DIYgod/RSSHub","slug":"vm-runinthiscontext-is-not-supported-in-workers","errorCode":null,"errorMessage":"vm.runInThisContext is not supported in Workers","messagePattern":"vm\\.runInThisContext is not supported in Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-module.ts","lineNumber":71,"sourceCode":"    }\n    runInNewContext() {\n        throw new Error('vm.Script.runInNewContext is not supported in Workers');\n    }\n    runInThisContext() {\n        throw new Error('vm.Script.runInThisContext is not supported in Workers');\n    }\n}\n\nconst vmShim = {\n    createContext: (sandbox?: object) => sandbox || {},\n    runInContext: () => {\n        throw new Error('vm.runInContext is not supported in Workers');\n    },\n    runInNewContext: () => {\n        throw new Error('vm.runInNewContext is not supported in Workers');\n    },\n    runInThisContext: () => {\n        throw new Error('vm.runInThisContext is not supported in Workers');\n    },\n    Script: ScriptShim,\n    isContext: () => false,\n    compileFunction: () => {\n        throw new Error('vm.compileFunction is not supported in Workers');\n    },\n};\n\n// Child process shim (inline to avoid import cycle)\nconst child_process = {\n    execSync: (_command: string): Buffer => Buffer.from(''),\n    exec: () => {\n        throw new Error('exec is not supported in Cloudflare Workers');\n    },\n    spawn: () => {\n        throw new Error('spawn is not supported in Cloudflare Workers');\n    },\n    fork: () => {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L53-L89","documentation":"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.","triggerScenarios":"Calling vm.runInThisContext(code) under Workers; some require-hook implementations and legacy eval wrappers.","commonSituations":"Migrated Node loaders; runtime self-modifying code; debugging hooks left enabled.","solutions":["Remove runInThisContext from Worker paths.","Use bundler-time module resolution instead.","Run on Node if the behavior is required."],"exampleFix":"// before\nvm.runInThisContext(code);\n// after\nimport * as mod from './mod'; // static, build-resolved","handlingStrategy":"validation","validationCode":"const vmUsable = typeof process !== 'undefined' && !!process.versions?.node;\nif (!vmUsable) {\n  // skip vm.runInThisContext; use static imports\n}","typeGuard":"function isVmShimError(e: unknown): e is Error {\n  return e instanceof Error && /not supported in Workers/.test(e.message);\n}","tryCatchPattern":"try {\n  if (vmUsable) vm.runInThisContext(code);\n  else return importedModule;\n} catch (e) {\n  if (isVmShimError(e)) return importedModule;\n  throw e;\n}","preventionTips":["Remove runtime self-eval from Worker code paths.","Resolve modules statically via the bundler.","Run require-hook style code only on Node."],"tags":["cloudflare-workers","vm","runtime","shim"],"backgroundTag":null,"analyzedSha":"bed535e0879dc71c5aff6f1e7bd1ac21ede40115","analyzedAt":"2026-08-12T19:29:35.364Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}