svgo: TypeError: Cannot read property 'toFixed' of undefined

Prozessing File:Pereslavl_narrow_gauge_railway_1990.svg with

svgo -i Pereslavl_narrow_gauge_railway_1990.svg -o output.svg --pretty --indent=1

leads to

TypeError: Cannot read property 'toFixed' of undefined at strongRound (C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\plugins\convertPathData.js:766:21) at C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\plugins\convertPathData.js:424:17 at Array.filter (<anonymous>) at filters (C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\plugins\convertPathData.js:272:17) at Object.exports.fn (C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\plugins\convertPathData.js:79:20) at C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\lib\svgo\plugins.js:61:45 at Array.filter (<anonymous>) at monkeys (C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\lib\svgo\plugins.js:48:39) at C:\Users\jkalliau\AppData\Roaming\npm\node_modules\svgo\lib\svgo\plugins.js:68:17 at Array.filter (<anonymous>) (Same as in https://github.com/svg/svgo/issues/987, except here I don’t specify convertPathData, therfore it is enabled.)


input.svg.txt input

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 2
  • Comments: 24 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Edit: The issue occurred with SVGs that contain <path d attribute values that use shorthand for decimals, omitting the zero integer.

When in your package.json a svgo release is used where this issue should have been fixed, but you still get this error, your project quite probably uses another package that indirectly uses an older/outdated svgo dependency. You can find this out by using the npm ls svgo command (not sure whether yarn supports this, too, I switched from yarn back to npm when npm became fast enough). This will list a dependency tree of the packages in the project that use the svgo package. In my case (roots.io Sage 9 base theme), the package css-loader required other old dependencies and one of them requires a very old package of svgo (css-loader is used for inlining SVGs in the CSS). Luckily there was already a newer version of css-loader available that requires newer dependency which themselves, in turn, require a recent svgo with this issue fixed.

So I’ve experienced this with babel-plugin-inline-react-svg today, but they won’t update their version of svgo because this library was updated to be asynchronous. Here’s an issue about that: https://github.com/svg/svgo/issues/1015 Is this essentially a catch-22 where neither library will make a move in either direction?

It was an easy fix for me to re-optimise my SVG to not strip the zero integer, but it may not always be that way…

Example of svg that triggers this error:

<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 40 40">
    <path d="M40.142 33.91L29.82 23.59a14.698 14.698 0 00.07-13.6 14.75 14.75 0 10-5.902 19.595l10.224 10.224 5.93-5.897zm-23.387-7.562a9.633 9.633 0 119.65-9.552 9.616 9.616 0 01-9.65 9.552z"/>
</svg>

Seems like no more an issue.

Yep, looks like this issue is fixed with v1.2.2

@dingo-d: Check your dependency tree for outdated svgo packages, see these instructions: https://github.com/svg/svgo/issues/990#issuecomment-570012473 gulp-imagemin may use its own, separate and outdated svgo dependency.

@trainoasis: Check your dependency tree for outdated svgo packages, see these instructions: https://github.com/svg/svgo/issues/990#issuecomment-570012473

This issue just popped up in my notifications. Has anyone edited or added something I hadn’t noticed?

@adam-hite it may be because of incorrect image. But as I see by stacktrace, there is outdated version of SVGO underhood.

Has the issue been fixed?

Need to keep in mind if upgrading that the issue exists in 1.3.0

Can confirm this is not an issue in v1.2.2