Leaflet "window is not defined" when working with Browserify due to use of "this"
See original GitHub issueI’m receiving the error “window not defined” which stems from leaflet’s use of this when referring to window. I have 0.7.3 of the npm leaflet version.
window is not defined
at Object.<anonymous> (/node_modules/leaflet/dist/leaflet-src.js:9180:3)
This issue references it but the issue does not seem to actually be resolved despite the closed status.
Issue Analytics
- State:
- Created 9 years ago
- Comments:17 (8 by maintainers)
Top Results From Across the Web
Node.js Leaflet error - Stack Overflow
It's an issue with Leaflet itself. Leaflet tries to load the DOM without checking if it's available or not. I think you can...
Read more >require is not defined babel | The AI Search Engine You Control
You're trying to use a CommonJS module from within your browser. This will not work. How are you using them? When you write...
Read more >Leaflet with browserify - Sigon - GitLab
This post will will show you how to build a very simple application that uses leaflet js with browserify. browserify logo ...
Read more >leaflet-src.js in extensions/piwigo-openstreetmap/leaflet
21, // define Leaflet as a global L variable, saving the original L to restore ... 514, // terrible browser detection to work...
Read more >leaflet - UNPKG
The best place to put your Leaflet plugin to is a separate [GitHub](http://github.com) repository. 27, If you create a collection ...
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
@dougajmcdonald @vincentaudebert This is what the
react-starter-kit
folks have to say about that:https://github.com/webpack/react-starter/issues/37#issuecomment-93943419
In other words, I’m making this not our (Leaflet’s) problem. If this is not reproducible with pure Browserify and no react, I’ll close the issue.
This issue might still arise in certain circumstances, e.g. protractor E2E testing.
Given you use ES6 or TS and import Leaflet as a module with
import * as Leaflet from "leaflet"
in a given class, when instantiating this class before the DOM is loaded you will receiveReferenceError: window is not defined
.The reason for instantiating this class depending on Leaflet before the DOM is ready could be to build objects for a test scenario. @mourner I believe this is worth considering in further iterations.