windmill-labs/windmill · error · Error

${main_name} function is missing

Error message

${main_name} function is missing

What it means

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.

Source

Thrown at backend/windmill-worker/src/bun_executor.rs:2048

    return [ {spread} ];
}}

function isAsyncIterable(obj) {{
    return obj != null && typeof obj[Symbol.asyncIterator] === 'function';
}}

BigInt.prototype.toJSON = function () {{
    return this.toString();
}};

async function run() {{
    {dates}
    {preprocessor}
    // If the entrypoint has no parsed params (spread is empty), pass values directly
    // This handles WAC child jobs where tasks are const-wrapped functions
    const argsArr = {child_spread};
    if (Main.{main_name} === undefined || typeof Main.{main_name} !== 'function') {{
        throw new Error("{main_name} function is missing");
    }}
    let entrypoint = Main.{main_name};
    let res = await entrypoint(...argsArr);
    if (isAsyncIterable(res)) {{
        for await (const chunk of res) {{
            console.log("WM_STREAM: " + chunk.replace(/\n/g, '\\n'));
        }}
        res = null;
    }}
    const res_json = JSON.stringify(res ?? null, (key, value) => typeof value === 'undefined' ? null : value);
    await fs.writeFile("result.json", res_json);
    process.exit(0);
}}
try {{
    await run();
}} catch(e) {{
    console.error(e);
    let err = {{ message: e.message, name: e.name, stack: e.stack }};

View on GitHub (pinned to e474e8803c)

Solutions

  1. Export a function named exactly as the entrypoint expects: `export function main(...) {...}` (or `export async function main`).
  2. Rename the local function back to `main` or update the script's entrypoint/signature setting to match.
  3. Check that no bundling/transform step strips or renames the export.

Example fix

// before
function main({ name }) { return `hi ${name}`; } // not exported
// after
export async function main({ name }) {
  return `hi ${name}`;
}
Defensive patterns

Strategy: validation

Validate before calling

// Verify the entrypoint export before deploy
if (!/export\s+(async\s+)?function\s+main\b|export\s+const\s+main\s*=/.test(source)) {
  throw new Error('Bun script must export a main function');
}

Try / catch

try {
  await windmill.runScript(path, hash_, args);
} catch (e) {
  if (/^[\w$]+ function is missing$/.test(e.message ?? '')) {
    console.error(`Export the entrypoint: export function ${e.message.split(' ')[0]}(...)`);
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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`.

Related errors


AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03). Data as JSON: /api/errors/c6308cfba9bf2dfa. Report an issue: GitHub.