Error when using ESM CDNs - `The requested module does not provide an export named 'toLatLngBounds'`
Closed this issue · 5 comments
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:
- This is possibly related or a duplicate of #1343
- This is similar or the same as what was discussed here.
- This was recently re-reported by @mbostock here.
- This is also tangentially related to #1338
Reproduction
esm.run reproduction:
- Open https://jsbin.com/xokuzam/1/edit?html,output
- 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:
to:
latLngBounds,
?
I have published a separate version of Esri Leaflet that includes the change:
to:
latLngBounds,
The good news is that when we change to the new version, the originally reported error does not show:
- Open https://jsbin.com/xokuzam/5/edit?html,output
- 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:
- Open https://jsbin.com/rahage/3/edit?html,output
- 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.
Hey @gavinr-maps
Does this issue still persist? If so could you please guide me through it, I'd love to give a hand but I'm kinda lost through the threads.
Thanks
Hi @Kizito007 I just followed the reproduction steps above and I still see the error showing (on the current version 3.0.12):
Turns out the fix that I mentioned in #1386 (comment) is the solution. But the follow-on issue is an issue with the CDN esm.run. If you switch it to use Cloudflare's esm.sh service, it works:
https://jsbin.com/rahage/7/edit?html,output
I will be issuing a PR shortly for that small change. No additional work needed on this issue.
Example of using Esri Leaflet with esm.sh CDN: https://jsbin.com/bapubuj/1/edit?html,output