react-leaflet-markercluster: Importing MarkerClusterGroup results in TypeError
I am receiving the following error when trying to use this package.
TypeError: Super expression must either be null or a function, not object
The entire error is shown here:

The error is associated with these lines of code in the react-leaflet-markcluster.js file (line numbers differ from what is shown in the error because of Chrome debugger formatting)

I am trying to use the package in a Gatsby project, but I don’t think that is causing the error. I am successfully able to import and use the react-leaflet project.
Version Info:
"react-leaflet": "^2.0.0",
"react-leaflet-markercluster": "^1.1.8",
"leaflet": "^1.3.1",
"leaflet.markercluster": "^1.3.0",
"gatsby": "^1.9.273",
Related Import Statements
import {
Map,
TileLayer,
Marker,
Popup,
} from 'react-leaflet';
import 'leaflet/dist/leaflet.css';
import MarkerClusterGroup from 'react-leaflet-markercluster/dist/react-leaflet-markercluster';
import 'react-leaflet-markercluster/dist/styles.min.css';
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 39 (10 by maintainers)
@webcarrot Many thanks for your contribution!
@reggie3 @oserban @ThiefMaster
Currently, the latest version with support of react-leaflet v2.0 and React 16.3 context API available as candidate release:
After the README and demo-app will be updated will publish it as release package.
P.S: it’s stable and I think there would no be any changes in final release, so enjoy it (=
Temporary version:
For me, with react-leaflet 2 worked solution from #issuecomment-403071677 (WITHOUT USING THIS PACKAGE react-leaflet-markercluster)
Dependencies version:
@webdobe
You need to install all peerDependencies:
Then install
nextrelease of that plugin:Previously try to remove
node_modulesand clean all lock files if you have them to reset prev. versions.@AliBayatpour - adding:
declare module ‘react-leaflet-markercluster’ { import { Component } from ‘react’;
}
to a global.d.ts file, fixed the “‘MarkerClusterGroup’ cannot be used as a JSX component” for me.
I was also getting type errors, e.g. “TypeError: Cannot read property ‘removeLayer’ of undefined”. However, using the code posted by @adambisek plus a css import, it seems to work. Here is the (slightly) modified code,
In case someone using Next.js stumbles upon here and use react-leaflet-universal (as I did), I confirm the rc3 works properly! You have to use next’s
dynamic()to import it client-side though.Deps :
import { withLeaflet,Marker} from "react-leaflet";Attempted import error: ‘withLeaflet’ is not exported from ‘react-leaflet’.Hello, @Riuborth
Currently, this wrapper does not work with react-leaflet v3 - the issue is already created
I will take a look at how it could be implemented with v3 during those weekends.
any contribution is welcome
UPD: The latest version with support of react-leaflet v3.0 available as a candidate release:
Hi.
props.leafletto be set/provided in MarkerClusterGroup instance contextValue.Sorry for my English.
@ThiefMaster yep, I will try to deliver it during the next week. The trick is that
react-leafletwas as the candidate release till that day.So since today, I need to update this lib. I will update
package.jsondependency to solve that issue in v1.1.9.And since v2.0 there will be support of
react-leaflet ^2.0latest React context from 16.3@asgaraliyev In case, if you are using v3 of
react-leaflet- that example is outdated, as it has been written for v2.@saadsaifse first result from googling “mapbox cluster” https://docs.mapbox.com/mapbox-gl-js/example/cluster/
@YUzhva
I’m still getting the above error and I’m using
2.0.0-rc3package.json
component
component.less