Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"MapboxGeocoder is not a constructor" when trying to initialize a MapboxGeocoder inside the ts of my component

I want to add the mapbox geocoding feature to my web app but when I try to initialize it the error comes in.

I've tried searching almost on every library inside the node_modules/mapbox-gl-geocoder for some constructor or something to see if I'm importing the wrong library but no success, If tried reading in the documentation but nothing either.

import  { MapboxGeocoder } from "mapbox-gl-geocoder";
.    
.
.
this.map.addControl(new MapboxGeocoder({
      accessToken: mapboxgl.accessToken
}));
like image 656
Jaime Ginorio Avatar asked Jan 27 '23 17:01

Jaime Ginorio


1 Answers

import * as MapboxGeocoder from '@mapbox/mapbox-gl-geocoder';

Solved the problem by replacing the current import with the one above.

like image 58
Jaime Ginorio Avatar answered Jan 30 '23 04:01

Jaime Ginorio