-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EventEmitter is not a constructor at new MapboxGeocoder (Next.JS & TypeScript) #493
Comments
I am having the same issue. Has anyone found a solution? The error I am getting is "Cannot set properties of undefined (setting '_eventEmitter')" Here is my code: `import Map from "react-map-gl"; const mapboxToken = process.env.REACT_APP_MAPBOX_KEY; export default function MapboxMap({ coordinates, mapMarkers, onGeoCodeResult, showSearchBox, style }){
}` |
I also had this issue while using migrating from Create React App to Vite. Resolved by |
events was needed for mapbox-gl-geocoder mapbox/mapbox-gl-geocoder#493 (comment)
events was needed for mapbox-gl-geocoder mapbox/mapbox-gl-geocoder#493 (comment)
I have been using MapboxGeocoder and it has worked fine previously. However, I am now getting this error:
EventEmitter is not a constructor at new MapboxGeocoder (webpack-internal:///./node_modules/@mapbox/mapbox-gl-geocoder/lib/index.js:87:24)
I am using these versions of mapbox-gl and mapbox-gl-geocoder:
These should be the up-to-date versions as of today (30/03/2023).
My code (simplified slightly):
The error occurs directly at the MapboxGeocoder constructor. It seems from the error message that the error might be TypeScript related. I saw that others have had the same issue, but all of them use Vite and Vue 3:
#441
https://stackoverflow.com/questions/69717406/typeerror-eventemitter-is-not-a-constructor-at-new-mapboxgeocoder
mapbox/mapbox-sdk-js#429
I have tried importing Events directly in my Map Component as such:
import EventEmitter from 'events';
I have also tried importing different versions, re-installing mapbox and geocoder, etc., but the issue persists.
Any ideas why this happens and how to solve it?
The text was updated successfully, but these errors were encountered: