oxc-project/oxc · error · OxcDiagnostic

Fast refresh only works when a file only exports components.

Error message

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.

What it means

Raised by react/only-export-components when a file exports both components and non-component values (constants, functions). React Fast Refresh only preserves state when a file exports components exclusively.

Source

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

use oxc_semantic::NodeId;
use oxc_span::{GetSpan, Span};
use rustc_hash::FxHashSet;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};

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)

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Move shared constants/functions to a separate module file.
  2. Keep only component exports in the component file.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/react/only_export_components.rs:22 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/c7b3f6d83c96286c. Report an issue: GitHub.