TypeError: Cannot read properties of undefined (reading '0')
Attached file issue41.svg gives this error:
TypeError: Cannot read properties of undefined (reading '0')
at Object.getPropertyDescriptor [as property] (C:\Users\<username>\AppData\Roaming\npm\node_modules\svgo\node_modules\csso\node_modules\css-tree\cjs\utils\names.cjs:69:24)
with this command
svgo issue41.svg
and also when opened here https://jakearchibald.github.io/svgomg/
(File is from the canvg test suite https://github.com/canvg/canvg/blob/master/test/svgs/issue41.svg )
The issue is ultimately that the file is a valid SVG, but has invalid styles, from what I understand.
Here is an MRE of the issue:
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 225, 425">
<path style="fill- opacity:0.5" d="M0 50 l50 50 0 20z"/>
</svg>
The parser encounters a CSS property, but the file jumps straight to declaring another CSS property rather than assigning a value to it.
(This appears to be done pseudo-accidentally in the test suite by putting a line break in the middle of the property name.)
I'm not sure if this should be resolved in CSSTree, CSSO, or SVGO. 🤔 Probably in CSSO or SVGO as it's ultimately invalid styles afaik, but I'll look into this further later. Just jotting notes down for now.
I also faced the same issue, the MRE that I come up with:
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 72 24">
<path d="M35 11 Q34.22 10.19 34.58 10.12 Q34.94 10.05 35.27 10.05 L35.27 10.05 Q35 10 36 10"/>
</svg>
traceback:
TypeError: Cannot read properties of undefined (reading '0')
at reflectPoint ([email protected]/node_modules/svgo/plugins/convertPathData.js:1160:37)
at [email protected]/node_modules/svgo/plugins/convertPathData.js:802:43
at Array.filter (<anonymous>)
at filters ([email protected]/node_modules/svgo/plugins/convertPathData.js:397:15)
at Object.enter ([email protected]/node_modules/svgo/plugins/convertPathData.js:183:20)
at visit ([email protected]/node_modules/svgo/lib/xast.js:52:30)
at visit ([email protected]/node_modules/svgo/lib/xast.js:68:9)
at visit ([email protected]/node_modules/svgo/lib/xast.js:61:7)
at invokePlugins ([email protected]/node_modules/svgo/lib/svgo/plugins.js:25:7)
at Object.fn ([email protected]/node_modules/svgo/lib/svgo/plugins.js:57:7)
I have the same issue, but only when I run over complete folder. It stops somewhere (every run differently) with the same error as @condemil and all processed SVG are empty. Processing each file individually works !?