Uncaught TypeError: Cannot read property 'classList' of undefined
See original GitHub issueIm using Leaflet with React, basically i wrote a wrapper of the library. When the React Wrapper is unmount I execute the following code:
this.map.eachLayer(function(layer) {
layer.remove();
});
this.map.remove();
Then the following error is thrown: Uncaught TypeError: Cannot read property ‘classList’ of undefined
The problem is in this function in leaflet-src.js:2336
function removeClass(el, name) {
if (el.classList !== undefined) {
el.classList.remove(name);
} else {
setClass(el, trim((' ' + getClass(el) + ' ').replace(' ' + name + ' ', ' ')));
}
}
It seems that the el parameter is null.
Expected behavior Component Unmount and no error is trigger
Current behavior The component unmount successfully but some kind of error is trigged:
Uncaught TypeError: Cannot read property ‘classList’ of undefined
Environment
- Leaflet version: 1.5.1
- Browser (with version): Chrome 71
- OS/Platform (with version): Linux Mint 19.2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:7 (3 by maintainers)
Top Results From Across the Web
TypeError: Cannot read property 'classList' of null
It means that document.getElementById("lastName") is returning undefined and you're trying to call classList on undefined itself.
Read more >TypeError: Cannot read property 'classList' of Null in JS
The "Cannot read property 'classList' of null" error occurs when trying to access the classList property on a null value. To solve the...
Read more >cannot read property 'classlist' of undefined javascript
But when I click on the radio button it doesn't show the content inside it and shows the "Cannot read property 'classList' of...
Read more >Cannot read property 'ClassList' of undefined - OutSystems
Hello Team,. I continuously facing Cannot read property 'ClassList' of undefined this error in browser. In my Master's and details screen.
Read more >Cannot read property 'classList' of null in Gatsbyjs - Reddit
Uncaught TypeError : Cannot read property 'classList' of null in Gatsbyjs. Hi there people! I am currently building a website for my ...
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
I tried to reproduce this error but I found no way how this can happens.
map._mapPane
is only “deleted” in themap.remove()
function but this also stops the animation. So it is not possible that_mapPane
isundefined
with only the Leaflet-Core code.I never worked with react, so my knowledge is very small but I tested it and I get no errors: https://codesandbox.io/s/leaflet-with-react-forked-dohc5d it is an older React version but it worked … Maybe because it is using
react-leaflet
?Until we find a reproducable example with vanilla Leaflet, we will close this.
Unfortunately, I am unable to reproduce it myself at the moment, but I do have stacktraces from Sentry: