{"record":{"id":"4d0ea3f1a03d2df3","repo":"oxc-project/oxc","slug":"ident-name-is-not-defined","errorCode":null,"errorMessage":"'{ident_name}' is not defined.","messagePattern":"'(.+?)' is not defined\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/react/jsx_no_undef.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{IdentifierReference, JSXElementName, JSXMemberExpression, JSXMemberExpressionObject},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::Rule,\n};\n\nfn jsx_no_undef_diagnostic(ident_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{ident_name}' is not defined.\")).with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct JsxNoUndef;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow undeclared variables in JSX.\n    ///\n    /// Note that this rule is generally unnecessary if you are using TypeScript, as\n    /// TypeScript will catch undeclared variables for you.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// It is most likely a potential ReferenceError caused by a misspelling of a variable or parameter name.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/react/jsx_no_undef.rs#L1-L34","documentation":"Diagnostic from react/jsx-no-undef (category: correctness). An identifier used inside JSX — a component tag (<Foo/>), or a reference inside an expression container — is not declared in scope (no import, variable, or global definition). The linter resolves the name against the module's scopes; JSX expression containers are treated like normal expressions, so undefined references there are flagged even though classic ESLint's no-undef did not look inside JSX without this rule. The rule's docs note it is largely redundant in TypeScript, where the compiler already catches undeclared variables.","triggerScenarios":"Rendering a component that was never imported: <Modal open={open}/>; referencing an undefined variable inside JSX: <div>{undefinedVar}</div>; using browser/Node globals (window is fine, but e.g. ga, dataLayer, process) that are not declared or not enabled in the lint environment/globals configuration.","commonSituations":"Auto-import failing when adding a component; copy-pasted JSX referencing helpers that were not copied; globals from analytics scripts or injected variables not listed in oxlint's globals/env config; projects where the rule duplicates what the TS compiler already reports.","solutions":["Add the missing import or declaration for the identifier","If the name is a legitimate global (e.g. an injected analytics object), declare it in .oxlintrc.json globals (or env) rather than silencing per line","If the identifier is only declared in a script type or ambient .d.ts, make sure that declaration is part of the linted project","In TypeScript projects where the compiler covers this, disable react/jsx-no-undef to remove duplicate reporting"],"exampleFix":"// before\nfunction App() {\n  return <Modal open={open}/>;\n}\n\n// after\nimport Modal from './Modal';\nimport { useOpen } from './state';\nfunction App() {\n  const open = useOpen();\n  return <Modal open={open}/>;\n}","handlingStrategy":"validation","validationCode":"npx oxlint -D react/jsx-no-undef src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Declare injected globals (analytics, dataLayer) in .oxlintrc.json globals instead of per-line disables","In TypeScript projects, rely on the compiler for undefined identifiers and disable this rule to avoid duplicate reports","Watch for auto-import failures in editors when adding new components — a quick oxlint pass catches what the editor missed"],"tags":["react","jsx","undefined-variable","imports","globals","oxlint","lint"],"backgroundTag":"jsx-undefined-identifier","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}