SVGInjector2 icon indicating copy to clipboard operation
SVGInjector2 copied to clipboard

TypeError: i is null / TypeError: Cannot read property 'split' of null

Open rotsee opened this issue 7 years ago • 5 comments

I get an error Uncaught TypeError: Cannot read property 'split' of null in Chrome, and TypeError: i is null [Learn More] in Firefox, given the following code:

<svg data-src="/images/test.svg" id="test"></svg>

document.addEventListener('DOMContentLoaded', function() {
  var elementsToInject = document.querySelectorAll('svg[data-src]');
  console.log(elementsToInject);
  # [svg#test]
  var injector = new SVGInjector();
  console.log(injector);
  # [svg#test]
  # n {}
  # XHR finished loading: GET "http://localhost:3000/images/test.svg".

  injector.inject(elementsToInject);
});

Any ideas how to trobleshoot this?

rotsee avatar Nov 21 '17 09:11 rotsee

Did you try with the latest version.. without investigation, this looks like a bug that has been fixed with 2.1.2. If the error persists, would you mind to share a gist with me, so I can debug this? Thank you!

flobacher avatar Nov 28 '17 07:11 flobacher

I used 2.1.3. Will try and reproduce!

rotsee avatar Dec 05 '17 14:12 rotsee

If anyone falls on this like me, it seems to be due to a wrong handling of the cases where the viewBox attribute is not present on the svg element.

twitwi avatar Jun 16 '19 13:06 twitwi

If anyone falls on this like me, it seems to be due to a wrong handling of the cases where the viewBox attribute is not present on the svg element.

Ha, I just had this issue today. Talk about good timing ^^ Thanks!

theRealPadster avatar Jun 17 '19 19:06 theRealPadster

yeah - just hit this problem. if you are using svgomg then it will strip the viewbox

brianteeman avatar Oct 06 '22 16:10 brianteeman