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.

Uncaught TypeError: Cannot read property 'classList' of undefined

See original GitHub issue

Im 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:closed
  • Created 4 years ago
  • Reactions:7
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Falke-Designcommented, Jul 17, 2022

I tried to reproduce this error but I found no way how this can happens. map._mapPane is only “deleted” in the map.remove() function but this also stops the animation. So it is not possible that _mapPane is undefined 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.

1reaction
leroydevcommented, Jun 22, 2022

@leroydev can you please share a stacktrace of the error?

Unfortunately, I am unable to reproduce it myself at the moment, but I do have stacktraces from Sentry: image

Read more comments on GitHub >

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

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