facebook/relay · error

Duplicate operation definitions named {}: first one: {:?}

Error message

Duplicate operation definitions named {}: 
first one: {:?}
second one: {:?}

What it means

Panic while building a ProgramWithDependencies from scoped definitions: two operation definitions share the same name within the scoped set; both source locations are printed. Operations must be globally unique per project, and this check enforces that before dependency-scoped compilation proceeds.

Source

Thrown at compiler/crates/program-with-dependencies/src/program_with_dependencies.rs:122

        fragment_signatures.extend(scoped_definitions.iter().filter_map(|def| {
            if let ExecutableDefinition::Fragment(fragment) = def {
                Some((fragment.name.item.clone(), fragment.into()))
            } else {
                None
            }
        }));
        let transformed_scoped_definitions =
            add_signatures_to_spreads(&fragment_signatures, scoped_definitions);

        let mut seen_operation_loc = HashMap::new();
        let mut seen_fragments_loc = HashMap::new();
        for definition in transformed_scoped_definitions {
            match definition {
                ExecutableDefinition::Operation(operation) => {
                    let loc = operation.name.location;
                    let name = operation.name.item;
                    if let Some(another) = seen_operation_loc.insert(name, loc) {
                        panic!(
                            "\nDuplicate operation definitions named {}: \nfirst one: {:?}\nsecond one: {:?}\n",
                            name, loc, another
                        );
                    }
                    scoped_operations.push(Arc::new(operation)); // Keep the order the operations same as inputs.
                }
                ExecutableDefinition::Fragment(fragment) => {
                    let loc = fragment.name.location;
                    let name = fragment.name.item;
                    let fragment_ref = Arc::new(fragment);
                    if let Some(another) =
                        seen_fragments_loc.insert(name, fragment_ref.name.location)
                    {
                        panic!(
                            "\nDuplicate fragment definitions named {}: \nfirst one: {:?}\nsecond one: {:?}\n",
                            name, loc, another
                        );
                    }

View on GitHub (pinned to 668b1b85e0)

Solutions

  1. Rename the colliding operations or remove the duplicate file
  2. Check project scoping config so the same operation isn't pulled into one compilation twice
  3. Verify overlapping --src directories aren't double-collecting documents
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at compiler/crates/program-with-dependencies/src/program_with_dependencies.rs:122 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of facebook/relay@668b1b85e0 (2026-09-02). Data as JSON: /api/errors/bc6b25b5d38eb034. Report an issue: GitHub.