oven-sh/bun · error · Error

Errors in .ts

Error message

Errors in ${basename}.ts:
${errors.map(x => x[1]).join("\n")}

What it means

Report error in bundle-functions.ts: after bundling a builtin module's functions, the generator collected per-function validation errors (the `errors` list of [name, message] pairs) and this message prints all of them together, prefixed by the originating builtin .ts basename. It aggregates earlier soft failures rather than failing on first error.

Solutions

  1. Read each per-function error line in the aggregated output and fix the named function in the reported builtin module
  2. If an error is a false positive of the hand-rolled validator, tighten the validation in bundle-functions.ts rather than the builtin source
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/codegen/bundle-functions.ts:337 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/848e7026b653e059. Report an issue: GitHub.

Appendix: source

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

    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)];
    if (errors.length) {
      throw new Error(`Errors in ${basename}.ts:\n${errors.map(x => x[1]).join("\n")}`);
    }

    bundledFunctions.push({
      name: fn.name,
      directives: fn.directives,
      source: finalReplacement,
      params: fn.params,
      // Async functions automatically get Private visibility because the parser
      // upgrades them when they use await (see Parser.cpp parseFunctionBody)
      visibility: fn.directives.visibility ?? (fn.directives.linkTimeConstant || fn.async ? "Private" : "Public"),
      constructAbility: fn.directives.ConstructAbility ?? "CannotConstruct",

      // Not known yet.
      sourceOffset: 0,

      overriddenName: fn.directives.getter
        ? `"get ${fn.name}"_s`
        : fn.directives.overriddenName

View on GitHub (pinned to 8c5296ac45)