MapBoxGL plugins

Has anyone had success importing plugins that run on top of the standard mapbox-gl package? I’m struggling to get them to import, like here

The documentation with this code seems to suggest this should work.

I’m sure I am missing something fundamental and/or obvious. Thanks in advance for any help.

Can’t investigate at the moment, but I have used the Mapbox geocoding API here:

Thanks for the rapid tip. I actually saw your workaround to hit the API directly there, which is pretty impressive. I should have mentioned I stumbled upon it. It is hardly a pressing matter, so please don’t interrupt your evening, but I’m curious to learn if anyone has been able to use require to import the full functionality of the geocoder package.

Hey Ben,

Sure thing - there are two tweaks required:

  • Mapbox includes a dist of a bundled single JavaScript file, but they don’t point to it with the unpkg field, so we need to load it specifically.
  • Then we need to add the CSS to make it look nice.

Here’s the diff:


Thanks for the help. So is this a minor oversight in their packaging config I could help them with by making a patch to their GitHub repo?

Yep! Adding a field like "unpkg": "dist/mapbox-gl-geocoder.min.js" to the package.json should do it.

PR filed

1 Like