{"record":{"id":"c6308cfba9bf2dfa","repo":"windmill-labs/windmill","slug":"main-name-function-is-missing","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/bun_executor.rs","lineNumber":2048,"sourceCode":"    return [ {spread} ];\n}}\n\nfunction isAsyncIterable(obj) {{\n    return obj != null && typeof obj[Symbol.asyncIterator] === 'function';\n}}\n\nBigInt.prototype.toJSON = function () {{\n    return this.toString();\n}};\n\nasync function run() {{\n    {dates}\n    {preprocessor}\n    // If the entrypoint has no parsed params (spread is empty), pass values directly\n    // This handles WAC child jobs where tasks are const-wrapped functions\n    const argsArr = {child_spread};\n    if (Main.{main_name} === undefined || typeof Main.{main_name} !== 'function') {{\n        throw new Error(\"{main_name} function is missing\");\n    }}\n    let entrypoint = Main.{main_name};\n    let res = await entrypoint(...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 fs.writeFile(\"result.json\", res_json);\n    process.exit(0);\n}}\ntry {{\n    await run();\n}} catch(e) {{\n    console.error(e);\n    let err = {{ message: e.message, name: e.name, stack: e.stack }};","sourceCodeStart":2030,"sourceCodeEnd":2066,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-worker/src/bun_executor.rs#L2030-L2066","documentation":"The generated Bun wrapper for regular scripts requires the module to export the designated entrypoint function (Main.<main_name>, e.g. `main`). If the export is absent or not a function, it throws '<main_name> function is missing' before invoking the script.","triggerScenarios":"A Bun script with a parsed signature that doesn't export `export function main(...)` (or whatever the configured entrypoint name is), exports it under a different name, or exports a non-function value.","commonSituations":"Deleting or renaming main, forgetting the export keyword, defining main as a non-exported helper, or copy-pasting code where the entrypoint got renamed while the script's signature still references `main`.","solutions":["Export a function named exactly as the entrypoint expects: `export function main(...) {...}` (or `export async function main`).","Rename the local function back to `main` or update the script's entrypoint/signature setting to match.","Check that no bundling/transform step strips or renames the export."],"exampleFix":"// before\nfunction main({ name }) { return `hi ${name}`; } // not exported\n// after\nexport async function main({ name }) {\n  return `hi ${name}`;\n}","handlingStrategy":"validation","validationCode":"// Verify the entrypoint export before deploy\nif (!/export\\s+(async\\s+)?function\\s+main\\b|export\\s+const\\s+main\\s*=/.test(source)) {\n  throw new Error('Bun script must export a main function');\n}","typeGuard":null,"tryCatchPattern":"try {\n  await windmill.runScript(path, hash_, args);\n} catch (e) {\n  if (/^[\\w$]+ function is missing$/.test(e.message ?? '')) {\n    console.error(`Export the entrypoint: export function ${e.message.split(' ')[0]}(...)`);\n  }\n  throw e;\n}","preventionTips":["Always `export` the main function — declaration alone is not enough.","Keep the export name identical to the script's configured entrypoint/signature.","Run the script once in the Windmill UI (same runtime) before programmatic use."],"tags":["bun","missing-export","entrypoint","scripts"],"backgroundTag":"missing-exported-function","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"}