{"record":{"id":"0243ad59cdac28c1","repo":"windmill-labs/windmill","slug":"main-name-function-is-missing-0243ad","errorCode":null,"errorMessage":"${main_name} function is missing","messagePattern":"(.+?) function is missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/windmill-worker/src/deno_executor.rs","lineNumber":355,"sourceCode":"\nfunction argsObjToArr({{ {spread} }}) {{\n    return [ {spread} ];\n}}\n\nBigInt.prototype.toJSON = function () {{\n    return this.toString();\n}};\n\nfunction isAsyncIterable(obj) {{\n    return obj != null && typeof obj[Symbol.asyncIterator] === 'function';\n}}\n\nasync function run() {{\n    {dates}\n    {preprocessor}\n    const argsArr = argsObjToArr(args);\n    if ({main_name} === undefined || typeof {main_name} !== 'function') {{\n        throw new Error(\"{main_name} function is missing\");\n    }}\n    let res: any = await {main_name}(...argsArr);\n    if (isAsyncIterable(res)) {{\n        for await (const chunk of res) {{\n            console.log(\"WM_STREAM: \" + chunk.replace(/\\n/g, '\\\\n'));\n        }}\n        res = null;\n    }}\n    const res_json = JSON.stringify(res ?? null, (key, value) => typeof value === 'undefined' ? null : value);\n    await Deno.writeTextFile(\"result.json\", res_json);\n    Deno.exit(0);\n}}\ntry {{\n    await run();\n}} catch(e) {{\n    let err = {{ message: e.message, name: e.name, stack: e.stack }};\n    let step_id = Deno.env.get(\"WM_FLOW_STEP_ID\");\n    if (step_id) {{","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-worker/src/deno_executor.rs#L337-L373","documentation":"Thrown from the generated `run()` wrapper when the script's main entrypoint (named by main_name, typically `main`) is undefined or not a function. The worker builds a wrapper that calls `{main_name}(...argsArr)`, and guards it so that a script without the expected exported entry function fails with a clear message instead of a confusing 'undefined is not a function' TypeError.","triggerScenarios":"Executing any Deno/TypeScript script whose source does not export a function with the configured entrypoint name (usually `main`) — e.g. no export at all, `export function Main()` with different casing, or the export is a non-callable value.","commonSituations":"New script created from an empty template without a `main` export; renaming `main` to something else while the script metadata still points to `main`; forgetting the `export` keyword; writing `main` as a top-level side-effect script with no function; language/entrypoint mismatch after switching script kind.","solutions":["Export a function named `main` from the script: `export async function main(args) { ... }`","Check the script's entrypoint setting (advanced options) matches the exported function name if you intentionally use a different name","Add the missing `export` keyword — `function main()` alone is not visible to the wrapper","Ensure the script was saved/deployed so the running version actually contains the export"],"exampleFix":"// before\nasync function main(x: number) {\n  return x * 2;\n} // not exported\n// after\nexport async function main(x: number) {\n  return x * 2;\n}","handlingStrategy":"validation","validationCode":"// guard in the script file itself:\nif (typeof main !== 'function') {\n  throw new Error('script must export a `main` function');\n}","typeGuard":"function hasMain(mod: Record<string, unknown>): mod is { main: (...args: unknown[]) => unknown } {\n  return typeof mod.main === 'function';\n}","tryCatchPattern":null,"preventionTips":["Always start Deno scripts from a Windmill template containing `export async function main(...)`","Never rename `main` without updating the script's entrypoint setting in advanced options","Add a CI check that each .ts script exports `main` before deploy (`wmill script push` validation)"],"tags":["deno","missing-main","entrypoint","worker"],"backgroundTag":"missing-main-export","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}