Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To resolve the TypeError "EventEmitter is not a constructor" while using Mapbox-gl-geocoder in Next.JS, you should try the following steps:

  1. Install the latest version of react-mapbox-gl and mapbox-gl.

  2. Make sure you have 'geocoder' in the import statement of the MapboxGeocoder component.

  3. Check your code for any instance where you're calling EventEmitter explicitly.

  4. Ensure that the MapboxGl.GeolocateControl and MapboxGl.NavigationControl components are imported from react-mapbox-gl and not mapbox-gl.

  5. Check if MapboxGl.supported() returns true before rendering the Mapbox component.

  6. You can also try wrapping the Mapbox component with the 'loadable' HOC (Higher Order Component) from the 'react-loadable' library.

If none of the above solutions work, try a clean installation of the entire package with their latest versions or revert to an older version where this issue was not present.