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.

Add entrypoint for ES modules to package

See original GitHub issue

Hi folks,

I’ve been digging around today trying to figure out why Webpack’s tree shaking magic did not appear to be working on Leaflet’s code. Digging back through the history here, I see the following historic PRs:

  • February 2018: #6021 adds ES6 Module support, and unlocking all the goodies that come alongside
  • March 2018: Leaflet/Leaflet.markercluster#874 is broken due to the lack of a global L
  • July 2018: #6239 was a hotfix removing support for ES6 modules due to the above

In the removal hotfix, there was a comment that “people who want to take advantage of tree shaking can opt-in by adding custom rules resolving Leaflet to dist/leaflet-src.esm.js.” I’ll freely admit that I’m struggling to figure out how to do that (it may be pretty clear to be fair; I’m really not up to date with the modern Javascript ecosystem.)

Ever since that hotfix, there’s been a few PRs attempting to reintroduce module support but they’ve all been closed with a link back to the removal hotfix, and no further discussion.

The Leaflet/Leaflet.markercluster#874 issue remains open, with recent (January this year) comments floating the ideas of:

  • A new major version release of Leaflet to enforce the removal of the L global variable
  • Updating plugins to automatically resolve L to the leaflet module, rather than requiring Leaflet to expose L as a global variable.

Beyond this chatter on the Markercluster repo, I haven’t seen any other discussion on how the Leaflet community is feeling about the lack of ES6 module support and the widespread (?) dependence on a global L. If I may, I’d like to be the one to bring these up for discussion.

Do we know what the remaining blockers are for:

  • Removing the global L
  • Bringing back ES6 module support?

And is there anything we can do make progress on these?

Thanks all, Rob

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:22
  • Comments:38 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
jonkoopscommented, Jul 6, 2022

I think we want to drop UMD builds and the global at some point (whether that’s 2.0 or some other future version). To maintain backwards compatibility we can provide a dedicated leaflet/globals import to restore the behavior.

Personally I’d like to work Leaflet towards an ‘ESM first’ library so that it can simply be imported directly from a web browser. New standards such as Import Maps will make this even easier.

5reactions
joelhickokcommented, Jun 22, 2022

I am not a contributor on this project, so I know I may not hold weight here. You have to remove the global L at some point to move forward. Whatever the solution is, I’m sure the talented people here can figure something out. I realize the plugin issue, but in my own dev world, Leaflet is one of the few libraries out there keeping my development and build pipelines 10 years behind.

And, actually, MANY of the Leaflet plugins I use these days (or the build tools) allow one to import the core objects/classes directly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using ES modules in Node.js - LogRocket Blog
Module files within packages can be accessed by appending a path to the package name. Another way is if the package's package. json...
Read more >
The JavaScript Modules Handbook – Complete Guide to ES ...
This article will show you all you need to know about ES Modules and Module ... Add the "index.js" JavaScript file to this...
Read more >
Using ES Modules (ESM) in Node.js: A Practical Guide (Part 2)
The entry point to the package, which is the file that loads when your import or require a package, is src/main.js (just like...
Read more >
How to Create a Hybrid NPM Module for ESM and CommonJS.
Generates a hybrid package for either ESM or CommonJS. Single Source Base. Author your code in ES6, ES-Next or Typescript using import and ......
Read more >
Is Entry Point, ES6 Modules - javascript - Stack Overflow
I still don't think it's an exact dupe, though, because that one isn't browser-specific, while this one is. – trysis. Jul 4, 2020...
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