oxc-project/oxc · error · OxcDiagnostic

Unexpected `super()` because `super` is not a constructor.

Error message

Unexpected `super()` because `super` is not a constructor.

What it means

The bad_super variant of constructor-super (crates/oxc_linter/src/rules/eslint/constructor_super.rs:54). It fires when super() is called but the `extends` target is not a constructable value — e.g. `extends null`, a variable holding a non-function, or an arrow function. Such a call throws 'Super constructor is not a constructor' (a TypeError) at runtime. The diagnostic attaches a secondary label built from SuperClassContext, which holds the superclass span and a static label string.

Source

Thrown at crates/oxc_linter/src/rules/eslint/constructor_super.rs:53

        .with_labels([
            span.primary_label("This path may call `super()` after it was already called."),
            first_super_span.label("`super()` was first called here."),
        ])
}

#[derive(Clone, Copy)]
struct SuperClassContext {
    span: Span,
    label: &'static str,
}

fn bad_super(span: Span, super_class_context: Option<SuperClassContext>) -> OxcDiagnostic {
    let mut labels = vec![span.primary_label("This `super()` call is invalid here.")];
    if let Some(context) = super_class_context {
        labels.push(context.span.label(context.label));
    }

    OxcDiagnostic::warn("Unexpected `super()` because `super` is not a constructor.")
        .with_help(
            "Remove the `super()` call or change the `extends` clause to a constructable superclass.",
        )
        .with_note(
            "`super()` calls the constructor of the superclass, but this class does not extend a constructable value.",
        )
        .with_labels(labels)
}

#[derive(Debug, Default, Clone)]
pub struct ConstructorSuper;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Requires `super()` calls in constructors of derived classes and disallows `super()` calls
    /// in constructors of non-derived classes.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Point `extends` at a real class or constructable function.
  2. For extends-null designs, drop the super() call and initialize `this` explicitly (Object.create / Reflect.construct), or drop extends null entirely.
  3. Fix the import or value that resolves to a non-constructor.

Example fix

// before
class A extends null {
  constructor() { super(); } // TypeError at runtime
}

// after
class A {
  constructor() { this.x = 1; }
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
{
  "rules": {
    "constructor-super": "error"
  }
}

Prevention

When it happens

Trigger: `class A extends null { constructor() { super(); } }`; `class B extends getBase() { constructor() { super(); } }` where getBase() may return null or an arrow function; extending a mistyped import that resolves to a non-constructor value.

Common situations: Dependency-injected base classes that can be null; 'abstract base' patterns written as extends null; broken or circular imports where the base binding is undefined.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/3ea930d7b2054b4b. Report an issue: GitHub.