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

喜你入骨 提交于 2019-12-11 05:14:12

问题


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
}));

回答1:


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

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



来源:https://stackoverflow.com/questions/54702192/mapboxgeocoder-is-not-a-constructor-when-trying-to-initialize-a-mapboxgeocoder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!