svgdotjs/svg.js

TypeError: Cannot read properties of undefined (reading 'call') for PATHs in NodeJS

banujan6 opened this issue · 8 comments

The <path> elements which has EMPTY d attribute throws,

pathHandlers[s].call(null,
[1] ^
[1]
[1] TypeError: Cannot read properties of undefined (reading 'call')

in below code

import { SVG } from '@svgdotjs/svg.js';
const canvas = SVG( svgString ); // throws error

Works Fine

<symbol overflow="visible" id="glyph1-1">
      <path style="stroke:none;" d="M 8.84375 -0.203125 L 7.8125 0.828125 L 6.53125 -0.453125 C 5.914062 -0.078125 5.207031 0.109375 4.40625 0.109375 C 3.269531 0.109375 2.328125 -0.242188 1.578125 -0.953125 C 0.828125 -1.671875 0.453125 -2.5625 0.453125 -3.625 C 0.453125 -4.695312 0.828125 -5.585938 1.578125 -6.296875 C 2.328125 -7.003906 3.269531 -7.359375 4.40625 -7.359375 C 5.519531 -7.359375 6.453125 -7.003906 7.203125 -6.296875 C 7.960938 -5.585938 8.34375 -4.695312 8.34375 -3.625 C 8.34375 -2.8125 8.101562 -2.082031 7.625 -1.4375 Z M 2.859375 -2.046875 C 3.265625 -1.640625 3.773438 -1.4375 4.390625 -1.4375 C 5.015625 -1.4375 5.523438 -1.640625 5.921875 -2.046875 C 6.328125 -2.460938 6.53125 -2.988281 6.53125 -3.625 C 6.53125 -4.269531 6.328125 -4.796875 5.921875 -5.203125 C 5.523438 -5.617188 5.015625 -5.828125 4.390625 -5.828125 C 3.773438 -5.828125 3.265625 -5.617188 2.859375 -5.203125 C 2.453125 -4.796875 2.25 -4.269531 2.25 -3.625 C 2.25 -2.988281 2.453125 -2.460938 2.859375 -2.046875 Z M 2.859375 -2.046875 "/>
</symbol>

Throws Error

<symbol overflow="visible" id="glyph1-0">
     <path style="stroke:none;" d=""/>
</symbol>

Environment

NodeJS v19.7.0, @svgdotjs/svg.js ^3.1.2, MacOS Ventura - M1

are you using svgdom?

Only In this part,

const { createSVGWindow } = require('svgdom');

global.window = createSVGWindow();
global.document = global.window.document;

// register window and document
registerWindow(window, document);

In that case you are completely using it :D. Will look into it when i have some time.
If you wanna help, you can check if the same error happens when running it in the browser

Sure, let me check.

@Fuzzyma It is not happening in the browser. Just node things..

Then its most likely a bug in svgdom. thanks for investigating!

Yeah let me dig into it further and try to add a fix. Thanks for your support.

@banujan6 I tried this myself and couldnt reproduce it. Do you have a full script that triggers the error?