oxc-project/oxc · error · OxcDiagnostic

JSX not allowed in files with extension '.{ext}'

Error message

JSX not allowed in files with extension '.{ext}'

What it means

Raised by react/jsx_filename_extension when the file being linted has an extension not in the rule's `allow` list (default jsx/tsx) yet contains JSX. At the throw site JSX in a file with an unexpected extension (e.g. `.js`) breaks tooling conventions — bundler resolution, editor tooling, and team norms expect JSX only in configured extensions. run_once() reads the file path, extracts its extension, and reports the module span when the extension is disallowed.

Source

Thrown at crates/oxc_linter/src/rules/react/jsx_filename_extension.rs:21

use itertools::Itertools;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use serde_json::Value;

use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;

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

fn no_jsx_with_filename_extension_diagnostic(
    ext: &str,
    span: Span,
    allowed_extensions: &[CompactStr],
) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("JSX not allowed in files with extension '.{ext}'"))
        .with_help(format!(
            "Rename the file to use an allowed extension: {}",
            allowed_extensions.iter().map(|e| format!(".{e}")).join(", ")
        ))
        .with_label(span)
}

fn extension_only_for_jsx_diagnostic(ext: &str, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn(format!("Only files containing JSX may use the extension '.{ext}'"))
        .with_help("Rename the file with a good extension.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, JsonSchema, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
enum JsxFilenameExtensionAllowMode {
    /// Always allow a JSX filename extension.
    #[default]

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Rename the file to an allowed extension (.jsx or .tsx).
  2. Add the current extension to the rule's allowedExtensions configuration.
  3. Move the JSX into a separate .jsx file.
Defensive patterns

Strategy: validation

When it happens

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