oxc-project/oxc · error · OxcDiagnostic

Fast refresh can't handle anonymous components. Add a name t

Error message

Fast refresh can't handle anonymous components. Add a name to your export.

What it means

Raised by react/only_export_components when an exported value is an anonymous component — a function without a usable name (e.g. `export default () => <div/>` or an unnamed function expression). At the throw site Fast Refresh relies on component names to match and re-render the right component between edits; with no name it cannot reconcile the module, forcing a full reload. anonymous_components_diagnostic fires from analyze_exports/analyze_export_declaration when the exported declaration's binding name cannot be resolved to a named React component.

Source

Thrown at crates/oxc_linter/src/rules/react/only_export_components.rs:27

use crate::{
    context::LintContext,
    rule::{DefaultRuleConfig, Rule},
    utils::is_react_component_name,
};

fn export_all_components_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("This rule can't verify that `export *` only exports components.")
        .with_label(span)
}

fn named_export_components_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.")
        .with_label(span)
}

fn anonymous_components_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(
        "Fast refresh can't handle anonymous components. Add a name to your export.",
    )
    .with_label(span)
}

fn local_components_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Fast refresh only works when a file only exports components. Move your component(s) to a separate file.")
        .with_label(span)
}

fn no_export_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Fast refresh only works when a file has exports. Move your component(s) to a separate file.")
        .with_label(span)
}

fn react_context_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Fast refresh only works when a file only exports components. Move your React context(s) to a separate file.")
        .with_label(span)

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Give the component a name: export default function MyComponent() {}.
  2. Assign the anonymous component to a named variable before exporting.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/only_export_components.rs:27 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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