Ask Your Question
3

How can the TypeError "EventEmitter is not a constructor" be resolved while using Mapbox-gl-geocoder in Next.JS?

asked 2023-07-19 01:49:12 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-07-19 02:12:02 +0000

scrum gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-07-19 01:49:12 +0000

Seen: 14 times

Last updated: Jul 19 '23