Sometimes, we want to fix the ‘Uncaught ReferenceError: React is not defined’ error when developing React apps.
In this article, we’ll look at how to fix the ‘Uncaught ReferenceError: React is not defined’ error when developing React apps.
Fix the ‘Uncaught ReferenceError: React is not defined’ Error When Developing React Apps
To fix the ‘Uncaught ReferenceError: React is not defined’ error when developing React apps, we can add the 'react'
property to the externals
property in webpack.config.json
.
To do this, we write:
externals: {
'react': 'React'
},
to tell Webpack that React
a global variable.
Also, we can add import React from 'react';
to the top of each component file to fix the error.
Conclusion
To fix the ‘Uncaught ReferenceError: React is not defined’ error when developing React apps, we can add the 'react'
property to the externals
property in webpack.config.json
.
Also, we can add import React from 'react';
to the top of each component file to fix the error.