HeatMap - 'google' is not defined and Module not found errors
See original GitHub issuePlease provide an explanation
HeatMap implementation results in two errors described below. I have tried using the Gatsby example but have the same issue. I am just trying to display on a simple one page app using CRA.
Your Environment
os: mac/linux/windows/
node --version v16.13.0
react version 18.0.0
@react-google-maps/api version 2.8.1
How is it behave?
I cannot get the heatmap later to display - getting two errors:
'google' is not defined
Module not found: Error: You attempted to import ../../docs/ScriptLoaded which falls outside of the project src/ directory.
How should it behave correctly?
Heatmap should render
basic implementation of incorrect behavior in codesandbox.com
https://codesandbox.io/s/kind-wescoff-ud7jb8?file=/src/App.js

import { GoogleMap, HeatmapLayer } from '@react-google-maps/api';
const ScriptLoaded = require('../../docs/ScriptLoaded').default;
const mapContainerStyle = {
height: '400px',
width: '800px',
};
const center = {
lat: 37.774546,
lng: -122.433523,
};
function App() {
const onLoad = (heatmapLayer) => {
console.log('HeatmapLayer onLoad heatmapLayer: ', heatmapLayer);
};
const onUnmount = (heatmapLayer) => {
console.log('HeatmapLayer onUnmount heatmapLayer: ', heatmapLayer);
};
return (
<div className="App">
<div className="map-container">
<ScriptLoaded>
{() => (
<GoogleMap
// optional
id="heatmap-layer-example"
// required to set height and width either through mapContainerClassName, either through mapContainerStyle prop
mapContainerStyle={mapContainerStyle}
// required
zoom={13}
// required
center={center}>
<HeatmapLayer
// optional
onLoad={onLoad}
// optional
onUnmount={onUnmount}
// required
data={[
new google.maps.LatLng(37.782, -122.447),
new google.maps.LatLng(37.782, -122.445),
new google.maps.LatLng(37.782, -122.443),
new google.maps.LatLng(37.782, -122.441),
new google.maps.LatLng(37.782, -122.439),
new google.maps.LatLng(37.782, -122.437),
new google.maps.LatLng(37.782, -122.435),
new google.maps.LatLng(37.785, -122.447),
new google.maps.LatLng(37.785, -122.445),
new google.maps.LatLng(37.785, -122.443),
new google.maps.LatLng(37.785, -122.441),
new google.maps.LatLng(37.785, -122.439),
new google.maps.LatLng(37.785, -122.437),
new google.maps.LatLng(37.785, -122.435),
]}
/>
</GoogleMap>
)}
</ScriptLoaded>
</div>
</div>
);
}
export default App;
Issue Analytics
- State:
- Created a year ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
Google Maps API throws "Uncaught ReferenceError
Uncaught ReferenceError : google is not defined error will be gone when removed the async defer from the map API script tag.
Read more >Google / HeatmapOverlay is not defined · Issue #218 · pa7 ...
Hi Guys,. I'm getting the above two errors, the first being within the 'gmaps-heatmap.js' file, and the second being when i create a...
Read more >Upgrading Your Maps JavaScript API Application from V2 to V3
The Maps JavaScript API v2 is no longer available as of May 26, 2021. As a result, your site's v2 maps will stop...
Read more >How to Fix: No module named plotly - Statology
This error occurs when Python does not detect the Plotly library in your current environment. This tutorial shares the exact steps you can...
Read more >NameError: name 'plt' is not defined in Python | bobbyhadz
Make sure you haven't misspelled the module you are importing because module names are case-sensitive. Also, make sure you haven't placed your import...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks