{"record":{"id":"7aa248951b6349a1","repo":"windmill-labs/windmill","slug":"preprocessor-function-is-missing","errorCode":null,"errorMessage":"preprocessor function is missing","messagePattern":"preprocessor function is missing","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"backend/windmill-worker/src/bun_executor.rs","lineNumber":1881,"sourceCode":"        };\n\n        let main_import = if codebase.is_some() || has_bundle_cache {\n            \"./main.js\"\n        } else {\n            \"./main.ts\"\n        };\n\n        let wac_client_import = if has_bundle_cache {\n            \"./main.js\"\n        } else {\n            \"windmill-client\"\n        };\n\n        let preprocessor = if let Some(pre_args) = pre_args {\n            let pre_spread = pre_args.into_iter().map(|x| x.name).join(\",\");\n            format!(\n                r#\"if (Main.preprocessor === undefined || typeof Main.preprocessor !== 'function') {{\n        throw new Error(\"preprocessor function is missing\");\n    }}\n    function preArgsObjToArr({{ {pre_spread} }}) {{\n        return [ {pre_spread} ];\n    }}\n    args = await Main.preprocessor(...preArgsObjToArr(args));\n    const args_json = JSON.stringify(args ?? null, (key, value) => typeof value === 'undefined' ? null : value);\n    await fs.writeFile('args.json', args_json, {{ encoding: 'utf8' }})\"#\n            )\n        } else {\n            \"\".to_string()\n        };\n\n        let wac_spread = if spread.is_empty() {\n            \"Object.values(args)\".to_string()\n        } else {\n            format!(\"argsObjToArr(args)\")\n        };\n","sourceCodeStart":1863,"sourceCodeEnd":1899,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/windmill-worker/src/bun_executor.rs#L1863-L1899","documentation":"When a script is configured with a preprocessor, the generated Bun wrapper checks that the entrypoint module (Main) exports a `preprocessor` function and that it is callable. If the export is missing or not a function, the wrapper throws 'preprocessor function is missing' at job start, before args are transformed.","triggerScenarios":"A Windmill script has preprocessor arguments configured (pre_args present), so the worker injects the wrapper, but the script's main module does not define `export function preprocessor(...)` or exports it under a different name / as a non-function.","commonSituations":"Adding preprocessor args in the UI without adding the preprocessor function to the code, copying code that dropped the export, misspelling `preprocessor`, or defining it as a const arrow function that isn't exported.","solutions":["Add `export function preprocessor(...) { ... }` (or `export const preprocessor = ...`) to the script's main module.","Ensure the export name is exactly `preprocessor` and it's exported, not just declared.","If no preprocessing is needed, remove the preprocessor args from the script's settings instead."],"exampleFix":"// before\nfunction preprocessor(args) { return transform(args); } // not exported\n// after\nexport async function preprocessor({ name, count }) {\n  return [name, count];\n}","handlingStrategy":"validation","validationCode":"// Before enabling preprocessor args, assert the export exists\nif (scriptHasPreprocessorArgs && !/export\\s+(async\\s+)?function\\s+preprocessor|export\\s+const\\s+preprocessor\\s*=/.test(source)) {\n  throw new Error('Script declares preprocessor args but does not export a preprocessor function');\n}","typeGuard":null,"tryCatchPattern":"// The throw happens inside the job; catch when awaiting the job result\ntry {\n  await windmill.runScript(path, hash_, args);\n} catch (e) {\n  if (e.message.includes('preprocessor function is missing')) {\n    console.error('Add: export function preprocessor(...) to the script, or remove preprocessor args');\n  }\n  throw e;\n}","preventionTips":["When adding preprocessor args in the UI, add the exported preprocessor function in the same change.","Use the WAC/script template that includes the preprocessor stub.","Grep the source for `export ... preprocessor` before deploying scripts with pre_args."],"tags":["bun","preprocessor","missing-export","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"}