oxc-project/oxc · warning
Duplicate key '{key}'
Error message
Duplicate key '{key}' What it means
This diagnostic comes from the `no_dupe_keys` rule in oxlint. It reports an object literal that defines the same key twice. The later value overwrites the earlier one at runtime, so the first pair is dead data. The rule stores each `PropertyKey` in a hash map and reports the second occurrence with labels on both spans.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_dupe_keys.rs:13
use oxc_ast::{
AstKind,
ast::{ObjectProperty, ObjectPropertyKind, PropertyKey, PropertyKind},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use rustc_hash::{FxBuildHasher, FxHashMap};
use crate::{AstNode, context::LintContext, rule::Rule};
fn no_dupe_keys_diagnostic(first: Span, second: Span, key: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Duplicate key '{key}'"))
.with_help("Consider removing the duplicated key")
.with_labels([
first.label("Key is first defined here"),
second.label("and duplicated here"),
])
}
#[derive(Debug, Default, Clone)]
pub struct NoDupeKeys;
declare_oxc_lint!(
/// ### What it does
///
/// Disallow duplicate keys in object literals.
///
/// This rule can be disabled for TypeScript code, as the TypeScript compiler
/// enforces this check.
///View on GitHub (pinned to e1e7af627c)
Solutions
- Delete one of the two pairs; the report labels the first definition and the duplicate.
- Rename one key when both values matter.
- Add a check to code review for large literal config objects.
Example fix
// before
const config = {
retries: 2,
timeout: 500,
retries: 5,
};
// after
const config = {
retries: 5,
timeout: 500,
}; Defensive patterns
Strategy: validation
Validate before calling
// no reliable runtime check: the engine collapses duplicate keys silently // run oxlint on the file instead: // oxlint src/config.js
Prevention
- Use TypeScript: a second identical key in one object literal is a compile error (ts1117).
- Run oxlint in the editor so duplicate keys show while you type.
- Build large option objects from small typed pieces, not by repeated literal edits.
When it happens
Trigger: An object literal with a repeated key: `{ a: 1, a: 2 }`, a quoted and unquoted mix `{ 'x': 1, x: 2 }`, or numeric forms that hold the same value such as `{ 1: 'a', 0x1: 'b' }`. Spread properties do not count.
Common situations: A config object grows over many commits, and two people add the same key. Keys are renamed during a migration and the old key stays in one place. Option groups are copied and pasted.
Related errors
- Duplicate class member: {member_name:?}
- Duplicate conditions in if-else-if chain
- Duplicate case label
- `debugger` statement is not allowed
- Variables should not be deleted
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/e5924b80cb26fe7a.
Report an issue: GitHub.