leaflet export broken in 1.8.0-beta.0
See original GitHub issueSteps to reproduce Steps to reproduce the behavior:
- import leaflet in a js file
- use a bundler like webpack or rollup to bundle the code
- load the bundle in any html file that does not have a div with id
leaflet
Expected behavior No error
Current behavior
Javascript Error: Uncaught ReferenceError: leaflet is not defined
Environment
- Leaflet version: 1.8.0-beta.0
- Browser (with version): Chrome 99.0.4844.51, Firefox 97.0.2
- OS/Platform (with version): Mac OS 12.2.1 (21D62)
Additional context
The problem seems to be that at the end of leaflet-src.js leaflet
is used instead of exports
now.
var oldL = window.L;
leaflet.noConflict = function() {
window.L = oldL;
return this;
}
// Always export us to window global (see #2364)
window.L = leaflet;
A fun little detail is that if you have a div with the id leaflet
in the html it is added to the global scope and everything works as intended. But I’m not sure yet why that fixes it.
Minimal example reproducing the issue https://github.com/Intermaps/leaflet-1.8.0-beta.0-export-bug
You can build with either webpack or rollup (I first thought the issue was related to my build process) and then open index.html
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
React-leaflet v3: How to fix the error 'You may ... - CodeSandbox
VS Code's tsserver was deleted by another application such as a misbehaving virus detection tool. Please reinstall VS Code. Manage Extension.
Read more >How to resolve the react-leaflet export error? - Stack Overflow
Here are the steps to follow to solve your issue: change your import to import { MapContainer as LeafletMap, TileLayer } from ...
Read more >Package List — Spack 0.20.0.dev0 documentation
butterflypack, perl-sub-exporter-progressive, r-ade4 ... Versions: 1.0.0-beta; Build Dependencies: gnuconfig, wxwidgets, fftw, libtiff; Link Dependencies: ...
Read more >Web Libraries in Jars - WebJars
angular-leaflet-directive, org.webjars, angular-leaflet-directive ... highcharts-export-csv, org.webjars.bower, github-com-CamdenClark-export-csv, 1.4.5.
Read more >export docker_buildkit=0 export compose_docker_cli_build=0
Support for BuildKit was just released in docker-compose 1.25.0. To enable: export ... Leaflet/Leafletleaflet export broken in 1.8.0-beta.0#8048.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Oh, you’re right, I missed that. That also explains why I couldn’t get the error in the plunkr.
Then it seems to only be a problem if leaflet is used with a bundling process like in the repository that I posted
I’ve updated the description of the bug accordingly
As workaround, import
leaflet-src.esm.js
(the ES-Module does not contain thenoConflict
code):You might need the following in a
index.d.ts
for TypeScript support: