oven-sh/bun · error · SyntaxError

Function has an unclosed generic type. Missing closing…

Error message

Function ${name} has an unclosed generic type. Missing ${depth} closing angle bracket(s).

What it means

SyntaxError in bundle-functions.ts: while consuming a function's type-parameter list, the bracket-depth counter never returned to zero before end of input — more `<` than `>`. The message names the function and how many closing angle brackets are missing, pointing at an unbalanced generic declaration in the builtin source.

Solutions

  1. Balance the generic type parameters in the reported function declaration
  2. If the source legitimately contains comparison operators that confuse the depth counter, parenthesize or restructure the signature
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bundle-functions.ts:221 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/908c8f2db94dad8b. Report an issue: GitHub.

Appendix: source

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

      var remaining = contents.slice(nameMatch[0].length);

      // remove type parameters
      if (remaining.startsWith("<")) {
        var cursor = 1; // skip peeked '<'
        var depth = 1; // already entered first bracket pair
        for (; depth > 0 && cursor < remaining.length; cursor++) {
          switch (remaining[cursor]) {
            case "<":
              depth++;
              break;
            case ">":
              depth--;
              break;
          }
        }

        if (depth > 0) {
          throw new SyntaxError(
            `Function ${name} has an unclosed generic type. Missing ${depth} closing angle bracket(s).`,
          );
        }
        remaining = remaining.slice(cursor).trimStart();
      }

      // parse function parameters
      assert(
        remaining.startsWith("("),
        new SyntaxError(`Function ${name} is missing parameter list start. Found:\n\n\t${remaining.slice(0, 100)}`),
      );
      const paramMatch = remaining.match(/^\(([^)]*)\)(?:\s*:\s*([^{\n]+))?\s*{?/);
      if (!paramMatch)
        throw new SyntaxError(
          `Could not parse parameters for function ${name}:\n` + contents.slice(0, contents.indexOf("\n")),
        );
      const paramString = paramMatch[1];
      const params =

View on GitHub (pinned to 8c5296ac45)