{"record":{"id":"4a2a10ba8cea927c","repo":"DIYgod/RSSHub","slug":"vm-script-runinthiscontext-is-not-supported-in-wor","errorCode":null,"errorMessage":"vm.Script.runInThisContext is not supported in Workers","messagePattern":"vm\\.Script\\.runInThisContext is not supported in Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-module.ts","lineNumber":58,"sourceCode":"import * as util_types from 'node:util/types';\nimport * as worker_threads from 'node:worker_threads';\nimport * as zlib from 'node:zlib';\n\n// VM shim for Cloudflare Workers\n// JSDOM and some other libraries require vm module\nclass ScriptShim {\n    private code: string;\n    constructor(code: string) {\n        this.code = code;\n    }\n    runInContext() {\n        throw new Error('vm.Script.runInContext is not supported in Workers');\n    }\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');","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L40-L76","documentation":"ScriptShim.runInThisContext() in lib/shims/node-module.ts throws — Workers forbid executing compiled code in the current context too. The whole Script execution surface is intentionally non-functional.","triggerScenarios":"Calling new vm.Script(code).runInThisContext() under Workers; some legacy require()-hooks and vm-based loaders use this entry point.","commonSituations":"Module loaders that compile wrappers; old code paths migrated from Node without runtime audit.","solutions":["Remove the runInThisContext call from Worker code paths.","Use static imports / bundler-resolved modules instead of runtime compilation.","Run the affected logic on the Node target."],"exampleFix":"// before\nnew vm.Script(code).runInThisContext();\n// after\nimport handler from './handler'; // resolved at build time","handlingStrategy":"validation","validationCode":"const vmUsable = typeof process !== 'undefined' && !!process.versions?.node;\nif (!vmUsable) {\n  // do not call 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) new vm.Script(code).runInThisContext();\n  else return staticHandler();\n} catch (e) {\n  if (isVmShimError(e)) return staticHandler();\n  throw e;\n}","preventionTips":["Replace runtime code compilation with build-time bundling.","Audit migrated Node loaders for runInThisContext usage.","Run eval-dependent paths 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-14T00:17:13.853Z"}