question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SVGs with missing width, height and viewbox cause errors

See original GitHub issue

If you try to add an SVG file without a width, height and viewBox element, the script returns an error exactly where it should report the missing file.

The file variable is used in a previous Promise function, but is no longer available (since the code has gone to a new then node).

I might write a PR for this, but don’t have the time right now.

https://github.com/cascornelissen/svg-spritemap-webpack-plugin/blob/93b68de6d99975c01945816eea8c7d858ac7ead6/lib/generate-svg.js#L131

A hotfix is to replace this line with a return; statement, but it’s not helping anyone solve the issue.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
roelofrcommented, Jan 28, 2019

Sorry @cascornelissen for the delay, the project I was using it in had taken a sharp turn when I spent too much time figuring this out.

I re-tried it in a different project (gumbo-millennium/website) and added this invalid SVG:

<svg xmlns="http://www.w3.org/2000/svg">
    <path fill="red" d="M0 0h64v64H0z"/>
</svg>

The result looks promising:

Error: Invalid SVG '/home/roelof/dev/gumbo/resources/assets/icons/square.svg'; it's lacking both a
 viewBox and width/height attributes...

edit

However, it also seems that WebPack isn’t too fond of not using Promise.catch, since it also spits out this beauty:

UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting
 a promise which was not handled with .catch(). (rejection id: 1)
0reactions
cascornelissencommented, Feb 23, 2020

@alpezed, I’m not 100% I understand but the svg-spritemap-webpack-plugin needs to know the height and width of each SVG that you want to end up in the spritemap. Without knowing the width/height of an SVG file it can’t calculate where the file should be placed in the generated spritemap.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css - SVG height incorrectly calculated in Webkit browsers
The issue is that although the SVG displays at the correct size (its' height being determined in ratio to the width, and as...
Read more >
SVG size issue after update - WordPress.org
Safe SVG has logic to get the height and width of an SVG from the height and width attributes. If those don't exist,...
Read more >
Here's How I Solved a Weird Bug Using Tried and True ...
The SVGs have been exported from a design tool and have no syntax errors. The SVGs have some CSS applied to them from...
Read more >
SVG with no explicit width and height is not rendered correctly ...
I would suggest a fallback to the viewbox attribute for width and height. 2 Likes. RaananW March 22, 2021, 7 ...
Read more >
Creating a responsive SVG with no aspect ratio | J Scott Smith
Just make sure to set the background-size to 100% if you want it to always fill to the edges. Additionally, you could limit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found