oxc-project/oxc · error · OxcDiagnostic
Only files containing JSX may use the extension '.{ext}'
Error message
Only files containing JSX may use the extension '.{ext}' What it means
Raised by react/jsx_filename_extension when configured with `allowAsRequired` and the file uses a JSX-permitting extension (like .jsx/.tsx) without containing any JSX. At the throw site the extension claims JSX content that is not there, which misleads module consumers and tooling about the file's contents. extension_only_for_jsx_diagnostic is produced by run_once() when the filename extension is allowed only for JSX files but no JSX element exists in the module.
Source
Thrown at crates/oxc_linter/src/rules/react/jsx_filename_extension.rs:30
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]
Always,
/// Only allow JSX filename extension for files that contain JSX syntax.
AsNeeded,
}
impl JsxFilenameExtensionAllowMode {
pub fn from(raw: &str) -> Self {
match raw {
"as-needed" => Self::AsNeeded,View on GitHub (pinned to e1e7af627c)
Solutions
- Rename the file to .js or .ts if it contains no JSX.
- Add JSX if the file was intended to contain markup.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/jsx_filename_extension.rs:30 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/fad1ff9474e12a36.
Report an issue: GitHub.