oven-sh/bun · error · Error

expected one output

Error message

expected one output

What it means

Post-build invariant in bundle-functions.ts: Bun.build succeeded but produced a number of outputs other than one. Since the tmp entry is a single synthetic file that bundles to exactly one chunk, any other count (zero, or extra chunks from code-splitting/dynamic imports) means the builtin function's source pulled in additional entry-like output and the capture step cannot proceed.

Solutions

  1. Remove dynamic imports or references that make the single tmp entry split into multiple outputs
  2. Disable code splitting for this build configuration so exactly one output chunk is produced
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bundle-functions.ts:317 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/96d2d344a528ccc5. Report an issue: GitHub.

Appendix: source

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

        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, "@")
        .replace(/__no_intrinsic__/g, "") + "\n";

    const errors = [...finalReplacement.matchAll(/@bundleError\((.*)\)/g)];

View on GitHub (pinned to 8c5296ac45)