{"record":{"id":"d1b94426f4af2cf6","repo":"oxc-project/oxc","slug":"react-must-be-in-scope-when-using-jsx","errorCode":null,"errorMessage":"`React` must be in scope when using JSX.","messagePattern":"`React` must be in scope when using JSX\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/react_in_jsx_scope.rs","lineNumber":14,"sourceCode":"use oxc_ast::AstKind;\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::static_ident;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::Rule,\n};\n\nfn react_in_jsx_scope_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"`React` must be in scope when using JSX.\")\n        .with_help(\"When using JSX, `<a />` expands to `React.createElement(\\\"a\\\")`. Therefore the `React` variable must be in scope.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct ReactInJsxScope;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Enforces that React is imported and in-scope when using JSX syntax.\n    ///\n    /// Note that this rule is **not necessary** on React 17+ if you are using\n    /// the new JSX Transform, and you can disable this rule and skip importing\n    /// `React` in files with JSX syntax.\n    ///\n    /// If your `tsconfig.json` has `jsx` set to `react-jsx` or `react-jsxdev`, you are using the new JSX Transform.\n    /// For JavaScript projects using Babel, you are using the new JSX Transform if your React preset configuration","sourceCodeStart":1,"sourceCodeEnd":32,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/react_in_jsx_scope.rs#L1-L32","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/react/react_in_jsx_scope.rs:14 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}