akursat / react-leaflet-cluster

React-leaflet-cluster is a plugin for react-leaflet. A wrapper component of Leaflet.markercluster.
MIT License
104 stars 36 forks source link

Runtime error 'TypeError: leaflet_1.default.MarkerClusterGroup is not a constructor' #20

Closed Lamap closed 1 year ago

Lamap commented 1 year ago

No compile error but getting this runtime error I wrote in the title.

My packages: "dependencies": { "@emotion/react": "^11.10.5", "@emotion/styled": "^11.10.5", "@mui/material": "^5.11.0", "@testing-library/jest-dom": "^5.16.5", "@testing-library/react": "^13.4.0", "@testing-library/user-event": "^13.5.0", "leaflet": "^1.8.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-leaflet": "^4.0.1", "react-leaflet-cluster": "^2.1.0", "react-leaflet-marker": "^2.1.0", "react-router-dom": "^6.5.0", "react-scripts": "5.0.1", "sass": "^1.56.2", "typescript": "^4.9.4" },

This is how my cluster group looks like: `

`

Appreciate any feedback, I might miss something trivial, but I suspect that there is some incompability with the versions. I have tried the react-leaflet-markercluster lib too, but I hit walls there too. I just would need some clustering solution instead implementing the wheel again...

akursat commented 1 year ago

Can you please create a codesanbox demo with your dependencies?

Lamap commented 1 year ago

Sure thing. I have created this, where I exactly copied every dependencies I have: https://codesandbox.io/s/react-leaflet-marker-cluster-m7i6cz?file=/src/components/map.tsx

I could not reproduce my issue however. FYI if I had not set the icon of the Markers, it thrown a runtime error.

Then I checked further the differences and figured out that in my implementation there was a MarkerLayer node that I removed what made it work.

My original plan was to use the clusterer with the react-leaflet-marker Marker what was not working, it thrown a runtime error. But it is another topic, anyway if you have any suggestions, links to some example I do appreciate that.

The relavant and maybe useful information for others is that not to use MarkerLayer next to the MarkerClusterGroup.