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.