oven-sh/bun · error · Error

This type already has required set

Error message

This type already has required set

What it means

Bindgen DSL guard: `.required` was accessed on a type already marked required. The duplicated flag indicates a mistaken type chain; codegen aborts instead of emitting the binding. (Note the following check for optional types is currently unreachable due to this early throw.)

Solutions

  1. Remove the duplicate `.required()` call in the chain
  2. If the type should be optional, remove required rather than re-deriving it
  3. Re-run codegen after fixing the definition
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at src/codegen/bindgen-lib-internal.ts:554 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/c46f4bc2f8017daa. Report an issue: GitHub.

Appendix: source

Thrown at src/codegen/bindgen-lib-internal.ts:554

    });
  }

  get finite() {
    if (this.kind !== "f64") {
      throw new Error("finite can only be used on f64");
    }
    if (this.flags.finite) {
      throw new Error("This type already has finite set");
    }
    return new TypeImpl(this.kind, this.data, {
      ...this.flags,
      finite: true,
    });
  }

  get required() {
    if (this.flags.required) {
      throw new Error("This type already has required set");
    }
    if (this.flags.required) {
      throw new Error("Cannot derive required on an optional type");
    }
    return new TypeImpl(this.kind, this.data, {
      ...this.flags,
      required: true,
    });
  }

  default(def: any) {
    if ("default" in this.flags) {
      throw new Error("This type already has a default value");
    }
    if (this.flags.required) {
      throw new Error("Cannot derive default on a required type");
    }
    this.assertDefaultIsValid(def);

View on GitHub (pinned to 8c5296ac45)