Categories
React Answers

How to fix Uncaught ReferenceError: React is not defined with React?

Spread the love

Sometimes, we want to fix Uncaught ReferenceError: React is not defined with React.

In this article, we’ll look at how to fix Uncaught ReferenceError: React is not defined with React.

How to fix Uncaught ReferenceError: React is not defined with React?

To fix Uncaught ReferenceError: React is not defined with React, we can change the Babel config.

For instance, we write

{
  "presets": [
    "@babel/preset-env",
    ["@babel/preset-react", { "runtime": "automatic" }]
  ]
}

to enable the React presets to run automatically at runtime to add React to where it’s needed in our code in .babelrc.

This works with React 17 and Babel.

Conclusion

To fix Uncaught ReferenceError: React is not defined with React, we can change the Babel config.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *