In this Q&A we troubleshoot why MapPress plugin reports React as undefined despite loading the library. We explore enqueueing React and ReactDOM in functions.php, checking Webpack externals and script order to restore plugin functionality.
I see this error in the console:
Uncaught ReferenceError: React is not defined
at index_mappress.js?ver=2.94.15:1:21733
at n (index_mappress.js?ver=2.94.15:1:87356)
at 327 (index_mappress.js?ver=2.94.15:1:86)
...
Error: Corruption: block checksum mismatch
A script on your site is trying to use React before it’s available. Let’s look at a few things you can check:
functions.php
or your plugin file and look for code like this:wp_enqueue_script(
'react',
'https://unpkg.com/react@17/umd/react.production.min.js',
array(),
'17.0.0',
true
);
wp_enqueue_script(
'react-dom',
'https://unpkg.com/react-dom@17/umd/react-dom.production.min.js',
array('react'),
'17.0.0',
true
);
wp_enqueue_script(
'mappress-script',
plugin_dir_url(__FILE__) . 'index_mappress.js',
array('react', 'react-dom', 'jquery'),
'2.94.15',
true
);
Make sure the react
and react-dom
handles appear before your plugin’s script and that they match the React version you need.
Search your codebase for other calls to enqueue React. Loading more than one version can break things.
In functions.php
, you can dump the script queue in the footer to verify order:
add_action('wp_footer', function() {
wp_print_scripts();
});
If index_mappress.js
uses JSX, confirm you have a build step (Webpack, Babel) that transpiles it to plain JavaScript.
Add this at the top of your plugin script to see if React is in scope:
console.log('React loaded:', typeof React);
These steps should get you closer to solving the issue.
React is reachable in the console, but the MapPress plugin still can’t find it.
If you can type React
in the console and get the library, yet MapPress complains it’s undefined, check these areas.
Some plugins wrap their code so globals aren’t visible. If MapPress uses Webpack, look for an externals
section in webpack.config.js
:
externals: {
react: 'React',
'react-dom': 'ReactDOM'
}
This tells Webpack to expect React globally rather than bundling it.
You might see React enqueued, yet MapPress runs too soon. Make sure your plugin’s script depends on React and ReactDOM:
wp_enqueue_script(
'mappress-script',
plugin_dir_url(__FILE__) . 'index_mappress.js',
array('react', 'react-dom'),
'2.94.15',
true
);
If MapPress injects an iframe, React must load inside that frame too.
Add this to your theme or a small plugin to attach React to window
after it loads:
add_action('wp_footer', function() {
echo '<script>window.React = React;</script>';
});
console.log('In MapPress:', typeof React);
at the very top of index_mappress.js
.By checking how the plugin is bundled and ensuring React is truly global in the right scope, you’ll get MapPress loading smoothly with React available.