ReferenceError: React is not defined
Error message
React is not defined
Quick summary
JSX requires React to be in scope (in older setups) or the automatic JSX runtime to be configured. This error means neither is satisfied.
Why this happens
Forgot to import React in a file using JSX (older transform)
Build tool not configured for the automatic JSX runtime
React import was accidentally removed
Minimal example
// No import
function App() {
return <div>Hello</div>; // React is not defined
}import React from "react";
function App() {
return <div>Hello</div>;
}With the classic JSX transform, React must be in scope. Adding the import fixes it. With the automatic runtime (React 17+), the import is added automatically.
How to diagnose
Check if
import React from 'react'is present at the top of the fileVerify the JSX transform setting in your build config (babel/tsconfig)
Check if the file uses JSX but has no React import
How to fix
Add
import React from 'react'at the top of the fileConfigure the automatic JSX runtime in your build tool
For TypeScript: set
jsx: 'react-jsx'in tsconfig.json
How to prevent
Use the automatic JSX runtime (React 17+) to avoid manual imports
Configure ESLint to detect missing React imports
Related Resources
Related Glossary
Related Lessons
- JSX Basics
Learn JSX setup and configuration.