oxc-project/oxc · error · OxcDiagnostic
`React` must be in scope when using JSX.
Error message
`React` must be in scope when using JSX.
What it means
Raised by react/react_in_jsx_scope when JSX is compiled with the classic `React.createElement` transform but no `React` binding is reachable in the module's scope. At the throw site the generated code will reference an undefined `React` identifier and crash at runtime ('React is not defined'); the diagnostic marks the JSX span where the missing reference originates. run() resolves JSX element references against the semantic scope tree and reports when the `React` import/require is absent.
Source
Thrown at crates/oxc_linter/src/rules/react/react_in_jsx_scope.rs:14
use oxc_ast::AstKind;
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use oxc_str::static_ident;
use crate::{
AstNode,
context::{ContextHost, LintContext},
rule::Rule,
};
fn react_in_jsx_scope_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("`React` must be in scope when using JSX.")
.with_help("When using JSX, `<a />` expands to `React.createElement(\"a\")`. Therefore the `React` variable must be in scope.")
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct ReactInJsxScope;
declare_oxc_lint!(
/// ### What it does
///
/// Enforces that React is imported and in-scope when using JSX syntax.
///
/// Note that this rule is **not necessary** on React 17+ if you are using
/// the new JSX Transform, and you can disable this rule and skip importing
/// `React` in files with JSX syntax.
///
/// If your `tsconfig.json` has `jsx` set to `react-jsx` or `react-jsxdev`, you are using the new JSX Transform.
/// For JavaScript projects using Babel, you are using the new JSX Transform if your React preset configurationView on GitHub (pinned to e1e7af627c)
Solutions
- Add `import React from "react"` at the top of the file.
- Migrate to the automatic JSX runtime (jsx: react-jsx) and disable this rule.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/react/react_in_jsx_scope.rs:14 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/d1b94426f4af2cf6.
Report an issue: GitHub.