Esri / esri-leaflet

A lightweight set of tools for working with ArcGIS services in Leaflet. :rocket:
https://developers.arcgis.com/esri-leaflet/
Apache License 2.0
1.6k stars 798 forks source link

Error when using ESM CDNs - `The requested module does not provide an export named 'toLatLngBounds'` #1386

Open gavinr-maps opened 7 months ago

gavinr-maps commented 7 months ago

Describe the bug

When trying to load Esri Leaflet via ES Modules via an ESM CDN like esm.sh or esm.run by jsDelivr, there is an error:

Uncaught SyntaxError: The requested module .... does not provide an export named 'toLatLngBounds' ...

Notes:

Reproduction

esm.run reproduction:

  1. Open https://jsbin.com/xokuzam/1/edit?html,output
  2. View the developer console
    • Expected: the map loads and no errors
    • Actual:

      Uncaught SyntaxError: The requested module '/npm/leaflet@1.9.4/+esm' does not provide an export named 'toLatLngBounds' (at +esm:7:265)

Logs

No response

System Info

- Leaflet v1.9.4
- Esri Leaflet v3.0.12

Additional Information

It does look like Leaflet exports as latLngBounds - https://github.com/Leaflet/Leaflet/blob/b2fd591c33785227e0d4036c1a80a00bd2debd53/src/geo/index.js#L2

... so is the fix as simple as changing this: https://github.com/Esri/esri-leaflet/blob/48cfd690614594428b09da284e30e08892a8ab6e/src/Layers/FeatureLayer/FeatureGrid.js#L3

to:

latLngBounds,

?

gavinr-maps commented 2 months ago

I have published a separate version of Esri Leaflet that includes the change:

https://github.com/Esri/esri-leaflet/blob/48cfd690614594428b09da284e30e08892a8ab6e/src/Layers/FeatureLayer/FeatureGrid.js#L3

to:

latLngBounds,

The good news is that when we change to the new version, the originally reported error does not show:

  1. Open https://jsbin.com/xokuzam/5/edit?html,output
  2. View the developer console
    • Expected: the map loads and no errors
    • Actual: the map loads and no errors

BUT if we add a feature layer to that map, we get a NEW error:

  1. Open https://jsbin.com/rahage/3/edit?html,output
  2. View the developer console
    • Expected: the map loads with a basemap and eartqualke feature points in USA
    • Actual: the map loads with a basemap, but no feature points in USA. error: TypeError: Cannot read properties of undefined (reading 'lat')

... so I'm not sure if this is the correct fix. or maybe we need an additional fix.