{"record":{"id":"c58e5fde052ed102","repo":"oven-sh/bun","slug":"all-top-level-functions-must-be-exported-fnname","errorCode":null,"errorMessage":"All top level functions must be exported: ${fnname}","messagePattern":"All top level functions must be exported: (.+?)","errorType":"exception","errorClass":"SyntaxError","httpStatus":null,"severity":"error","filePath":"src/codegen/bundle-functions.ts","lineNumber":275,"sourceCode":"          if (source.includes(name)) {\n            constEnumsUsedInFunction.push(code);\n          }\n        }\n      }\n\n      functions.push({\n        name,\n        params,\n        directives,\n        source,\n        async,\n        enums: constEnumsUsedInFunction,\n      });\n      contents = rest;\n      directives = {};\n    } else if (match[1] === \"function\" || match[1] === \"async function\") {\n      const fnname = contents.match(/^function ([a-zA-Z0-9]+)\\(([^)]*)\\)(?:\\s*:\\s*([^{\\n]+))?\\s*{?/)![1];\n      throw new SyntaxError(\"All top level functions must be exported: \" + fnname);\n    } else {\n      throw new Error(\"TODO: parse \" + match[1]);\n    }\n  }\n\n  for (const fn of functions) {\n    const tmpFile = path.join(TMP_DIR, `${basename}.${fn.name}.ts`);\n\n    // not sure if this optimization works properly in jsc builtins\n    // const useThis = fn.usesThis;\n    const useThis = true;\n\n    // TODO: we should use format=IIFE so we could bundle imports and extra functions.\n    await Bun.write(\n      tmpFile,\n      `// @ts-nocheck\n// GENERATED TEMP FILE - DO NOT EDIT\n// Sourced from ${path.relative(TMP_DIR, filename)}","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/oven-sh/bun/blob/8c5296ac459e8252d3cd702f3fbcbb0c249d95d5/src/codegen/bundle-functions.ts#L257-L293","documentation":"Error \"All top level functions must be exported: ${fnname}\" thrown in oven-sh/bun.","triggerScenarios":"Thrown at src/codegen/bundle-functions.ts:275 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8c5296ac459e8252d3cd702f3fbcbb0c249d95d5","analyzedAt":"2026-08-16T08:01:58.794Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}