Skip to content

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

✗ Broken code
// No import
function App() {
  return <div>Hello</div>; // React is not defined
}
✓ Fixed code
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 file

  • Verify 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 file

  • Configure 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

← Back to language