oxc-project/oxc · warning

Duplicate class member: {member_name:?}

Error message

Duplicate class member: {member_name:?}

What it means

This diagnostic comes from the `no_dupe_class_members` rule in oxlint. It reports two members with the same name in one class body. At runtime the last member overwrites the earlier one, so the earlier member is dead code. The rule keeps member names in a hash map and reports each re-declaration with labels on both the first and the second span.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_dupe_class_members.rs:13

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use rustc_hash::FxHashMap;

use crate::{context::LintContext, rule::Rule};

fn no_dupe_class_members_diagnostic(
    member_name: &str, /*Class member name */
    decl_span: Span,
    re_decl_span: Span,
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Duplicate class member: {member_name:?}"))
        .with_help("The last declaration overwrites previous ones, remove one of them or rename if both should be retained")
        .with_labels([
            decl_span.label(format!("{member_name:?} is previously declared here")),
            re_decl_span.label(format!("{member_name:?} is re-declared here")),
        ])
}

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

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow duplicate class members.
    ///
    /// This rule can be disabled for TypeScript code, as the TypeScript compiler
    /// enforces this check.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove one of the two members, or rename one if both are needed.
  2. If branches were merged, compare both bodies and keep the correct one.
  3. Use the two labels in the report to jump to the first declaration and to the re-declaration.
  4. Suppress in generated code with `// oxlint-disable-next-line no-dupe-class-members`.

Example fix

// before
class Repo {
  find(id) { return db.find(id); }
  find(id) { return this.all().filter(x => x.id === id); }
}

// after
class Repo {
  findById(id) { return db.find(id); }
  findAllById(id) { return this.all().filter(x => x.id === id); }
}
Defensive patterns

Strategy: validation

Validate before calling

// codegen check: duplicate plain member names in a class body
const names = [...clsSrc.matchAll(/(?:^|\n)\s*(?:get\s+|set\s+|static\s+|async\s+|\*\s*)*([A-Za-z_$][\w$]*)\s*\(/g)].map(m => m[1]);
const dup = names.filter((n, i) => names.indexOf(n) !== i);
if (dup.length) throw new Error('duplicate class members: ' + dup);

Prevention

When it happens

Trigger: Two methods, fields, or constructors with the same name in one class: `class A { foo() {} foo() {} }`. Getter/setter pairs with the same name form one property and stay allowed. The rule keys on the evaluated member name string.

Common situations: A merge conflict resolves to two methods with the same name. A method is copied with a plan to rename it, and the rename is forgotten. A large class hides the collision because the two members sit screens apart.

Related errors


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