google-map-react icon indicating copy to clipboard operation
google-map-react copied to clipboard

TypeError: Cannot read properties of undefined (reading 'dispose')

Open SergeyArenzon opened this issue 3 years ago • 13 comments

After upgrading to react@18 my google maps crashing on render.

Component code:

import GoogleMapReact from "google-map-react";
import markerSvg from "../../assets/images/google_maps_mark.svg";

const { REACT_APP_PUBLIC_GOOGLE_MAPS_API_KEY } = process.env;


const Map = ({ lat, lng})=> {

  return (
    <div style={{ height: "400px", width: "400px" }}>
      <GoogleMapReact
        bootstrapURLKeys={{ key: REACT_APP_PUBLIC_GOOGLE_MAPS_API_KEY}}
        defaultCenter={{ lat, lng }}
        defaultZoom={11}
      >
        <img
          src={markerSvg}
          lat={lat}
          lng={lng}
          text="My Marker"
          alt="marker"
        />
      </GoogleMapReact>
    </div>
  );
}

export default Map;

Errors screenshots https://ibb.co/bsGV76c https://ibb.co/ZGBhV8B https://ibb.co/X5vNTt5

OS: [mac] Browser [any browser]

SergeyArenzon avatar May 07 '22 14:05 SergeyArenzon

Any updates?!? I am also having the same issue....

lexcraw4d avatar Jun 04 '22 20:06 lexcraw4d

same issue

lemmen6 avatar Jun 07 '22 11:06 lemmen6

Try removing <React.StrictMode></React.StrictMode> from your index.js file

AtaydeEnrique avatar Jun 09 '22 02:06 AtaydeEnrique

Same issue

CyrilScript avatar Sep 28 '22 07:09 CyrilScript

Hi. Is there any way to fix it without removing <React.StrictMode> from index.js file? Thanks

fatihyildizhan avatar Oct 02 '22 08:10 fatihyildizhan

Does anyone have the same problem in vite?

Michael-indochat avatar Jan 03 '23 10:01 Michael-indochat

I'm having the same issue. I noticed it occurs when changing the route and the current react component that has the GoogleMapReact is being destroyed (I hope this might help to solve it)

Bartaf83 avatar Jan 04 '23 15:01 Bartaf83

Does anyone have the same problem in vite?

I'm experiencing this with Vite right now.

TS22082 avatar Jan 11 '23 19:01 TS22082

Try removing Suspense & lazy loading

pyjun01 avatar Jan 20 '23 04:01 pyjun01

Yes, same issue here with Vite. We have to remove React.StrictyMode to make it work.

Kirantechcs avatar Jan 23 '23 06:01 Kirantechcs

Hi. Is there any way to fix it without removing <React.StrictMode> from index.js file? Thanks

lalkrishnaa avatar Feb 28 '23 10:02 lalkrishnaa

this repo is i think pretty much dead. i would recommend anyone stumble upon this to try --> https://github.com/JustFly1984/react-google-maps-api

ev3nst avatar Mar 09 '23 11:03 ev3nst

I had to change and use '@react-google-maps/api' which worked perfectly fine

The introduction of lazy loading and suspense to my project caused the issue to occur when changing routes and the current react component that has the GoogleMapReact is being destroyed.

katherine95 avatar Jul 27 '23 23:07 katherine95