question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

leaflet export broken in 1.8.0-beta.0

See original GitHub issue

Steps 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:closed
  • Created 2 years ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
Eschoncommented, Mar 10, 2022

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

0reactions
simon04commented, Mar 10, 2022

As workaround, import leaflet-src.esm.js (the ES-Module does not contain the noConflict code):

import * as L from "leaflet/dist/leaflet-src.esm.js"

You might need the following in a index.d.ts for TypeScript support:

declare module "leaflet/dist/leaflet-src.esm.js" {
  export * from "leaflet";
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found