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
- 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.
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
- 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.
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
- preprocessor function is missing
- path and hash_ are mutually exclusive
- path or hash_ must be provided
- No workflow() entrypoint found. Wrap your main function with
- preprocessor function is missing
AI-assisted analysis of windmill-labs/windmill@e474e8803c (2026-09-03).
Data as JSON: /api/errors/c6308cfba9bf2dfa.
Report an issue: GitHub.