{"record":{"id":"ace95533b963104c","repo":"DIYgod/RSSHub","slug":"vm-compilefunction-is-not-supported-in-workers","errorCode":null,"errorMessage":"vm.compileFunction is not supported in Workers","messagePattern":"vm\\.compileFunction is not supported in Workers","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"lib/shims/node-module.ts","lineNumber":76,"sourceCode":"        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: () => {\n        throw new Error('fork is not supported in Cloudflare Workers');\n    },\n    execFile: () => {\n        throw new Error('execFile is not supported in Cloudflare Workers');\n    },","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/DIYgod/RSSHub/blob/bed535e0879dc71c5aff6f1e7bd1ac21ede40115/lib/shims/node-module.ts#L58-L94","documentation":"vmShim.compileFunction() in lib/shims/node-module.ts throws. Workers cannot compile a string into a callable Function at runtime via the vm API (no V8 compileFunction exposed), so the call is hard-fail.","triggerScenarios":"Calling vm.compileFunction(source, params) under Workers — used by some module systems and meta-templating libraries to build functions from source.","commonSituations":"Custom module loaders; DSL/template compilers built on vm.compileFunction.","solutions":["Replace vm.compileFunction with a build-time compiled function or new Function (only if Workers' CSP allows).","Static-import the compiled result instead.","Keep the code path Node-only."],"exampleFix":"// before\nconst fn = vm.compileFunction(src, ['x']);\n// after\nimport compiledFn from './compiled'; // produced at build time","handlingStrategy":"validation","validationCode":"const vmUsable = typeof process !== 'undefined' && !!process.versions?.node;\nif (!vmUsable) {\n  // skip vm.compileFunction; use a build-time compiled function\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) return vm.compileFunction(src, ['x']);\n  else return precompiled;\n} catch (e) {\n  if (isVmShimError(e)) return precompiled;\n  throw e;\n}","preventionTips":["Do not build functions from source at runtime under Workers.","Compile DSLs/templates at build time instead.","Keep vm-based compilers on the Node target."],"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"}