Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Uncaught (in promise) TypeError: Cannot read property 'width' of undefined at saveSvgAsPng.js:265 #241

Open
mqsmith opened this issue Feb 3, 2020 · 1 comment

Comments

@mqsmith
Copy link

mqsmith commented Feb 3, 2020

I am getting an uncaught error. This error is being thrown on the return of the inlineImages promise. I was wondering what it is trying to get the width of. I don't think I have any undefined heights or widths in my SVG.

@exupero
Copy link
Owner

exupero commented Feb 4, 2020

Strange. The only thing that block of code gets the width of is an Image object it creates (see line 134 here):

        const canvas = document.createElement('canvas');
        const img = new Image();
        img.crossOrigin = 'anonymous';
        img.src = href;
        img.onerror = () => reject(new Error(`Could not load ${href}`));
        img.onload = () => {
          canvas.width = img.width;
          canvas.height = img.height;
          canvas.getContext('2d').drawImage(img, 0, 0);
          image.setAttributeNS('http://www.w3.org/1999/xlink', 'href', canvas.toDataURL('image/png'));
          resolve(true);
        };

img shouldn't be undefined. Can you debug to make sure this is where the error is coming from or get any more details about how?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants