{"record":{"id":"04b2e5a6929465b2","repo":"DIYgod/RSSHub","slug":"vm-runincontext-is-not-supported-in-workers","errorCode":null,"errorMessage":"vm.runInContext is not supported in Workers","messagePattern":"vm\\.runInContext is not supported in Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-module.ts","lineNumber":65,"sourceCode":"    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');\n    },\n};\n\n// Child process shim (inline to avoid import cycle)\nconst child_process = {\n    execSync: (_command: string): Buffer => Buffer.from(''),\n    exec: () => {","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L47-L83","documentation":"Top-level vmShim.runInContext() in lib/shims/node-module.ts throws. Unlike createContext() (which returns the sandbox unchanged) and isContext() (returns false), the execution functions are hard-fail because Workers cannot run vm code. The shim mirrors Node's vm module shape but only the non-executing members are usable.","triggerScenarios":"Calling vm.runInContext(code, sandbox) directly (not via new Script) under Workers — common in older sandboxing/eval utilities.","commonSituations":"JSDOM-style or vm2-style callers using the functional vm API; template renderers that compile+run in one step.","solutions":["Eliminate vm.runInContext usage from Worker-deployed code.","Switch to a non-eval implementation (string templating, precompiled handlers).","Reserve this code path for the Node runtime."],"exampleFix":"// before\nvm.runInContext(compiledCode, sandbox);\n// after\nconst out = renderTemplate(tplString, data); // pure-string, no eval","handlingStrategy":"validation","validationCode":"const vmUsable = typeof process !== 'undefined' && !!process.versions?.node;\nif (!vmUsable) {\n  // skip vm.runInContext; use string templating\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.runInContext(code, ctx);\n  else return render(template, data);\n} catch (e) {\n  if (isVmShimError(e)) return render(template, data);\n  throw e;\n}","preventionTips":["Do not use the functional vm.run* APIs under Workers.","Use pure-string templating instead of eval-based rendering.","Reserve vm callers for 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"}