oven-sh/bun · error · AggregateError

Failed bundling builtin function ${fn.name} from ${basename}

Error message

Failed bundling builtin function ${fn.name} from ${basename}.ts

What it means

Error "Failed bundling builtin function ${fn.name} from ${basename}.ts" thrown in oven-sh/bun.

Source

Thrown at src/codegen/bundle-functions.ts:314

($);

$$capture_start$$(${fn.async ? "async " : ""}${
        useThis
          ? `function(${fn.params.join(",")})`
          : `${fn.params.length === 1 ? fn.params[0] : `(${fn.params.join(",")})`}=>`
      } {${fn.source}}).$$capture_end$$;
`,
    );
    await Bun.sleep(1);
    const build = await Bun.build({
      entrypoints: [tmpFile],
      define,
      target: "bun",
      minify: { syntax: true, whitespace: false, keepNames: true },
    });
    // TODO: Wait a few versions before removing this
    if (!build.success) {
      throw new AggregateError(build.logs, "Failed bundling builtin function " + fn.name + " from " + basename + ".ts");
    }
    if (build.outputs.length !== 1) {
      throw new Error("expected one output");
    }
    let output = (await build.outputs[0].text()).replaceAll("// @bun\n", "");
    let usesDebug = output.includes("$debug_log");
    let usesAssert = output.includes("$assert");
    const captured = output.match(/\$\$capture_start\$\$([\s\S]+)\.\$\$capture_end\$\$/)![1];
    const finalReplacement =
      captured
        .replace(
          /function\s*\(.*?\)\s*{/,
          '$&"use strict";' +
            (usesDebug ? createLogClientJS("BUILTINS", fn.name) : "") +
            (usesAssert ? createAssertClientJS(fn.name) : ""),
        )
        .replace(/^\((async )?function\(/, "($1function (")
        .replace(/__intrinsic__/g, "@")

View on GitHub (pinned to 8c5296ac45)

When it happens

Trigger: Thrown at src/codegen/bundle-functions.ts:314 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oven-sh/bun@8c5296ac45 (2026-08-16). Data as JSON: /api/errors/300123debf779288. Report an issue: GitHub.