withastro / astro

The web framework for content-driven websites. ⭐️ Star to support our work!
https://astro.build
Other
46.77k stars 2.48k forks source link

Astro glob throw unsupported files for svg #10913

Closed Its-Just-Nans closed 6 months ago

Its-Just-Nans commented 6 months ago

Astro Info

Astro                    v4.7.0
Node                     v18.18.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

Describe the Bug

Astro glob throw unsupported files for svg

const svgs = await Astro.glob("../files/*.svg")

throws

unsupported file type: undefined

What's the expected result?

Detect and import svgs

Link to Minimal Reproducible Example

https://stackblitz.com/edit/astro-vexf1b

Grohotun commented 6 months ago

I have almost the same error, but I do get object. But it's siblings are not having props, so even simple url to file is not working.

image

in dev mode it shows no images.

Its-Just-Nans commented 6 months ago

@Grohotun

In fact, it's when a svg doesn't have width or height specified ;)

The PR https://github.com/withastro/astro/pull/10924 add a clearer error message

Grohotun commented 6 months ago

@Grohotun

In fact, it's when a svg doesn't have width or height specified ;)

The PR #10924 add a clearer error message

@Its-Just-Nans setting width & height doesn't help at all.

Its-Just-Nans commented 6 months ago

@Grohotun

In fact, it's when a svg doesn't have width or height specified ;)

The PR #10924 add a clearer error message

@Its-Just-Nans setting width & height doesn't help at all.

Can you provide the svg ?

Grohotun commented 6 months ago

@Grohotun In fact, it's when a svg doesn't have width or height specified ;) The PR #10924 add a clearer error message

@Its-Just-Nans setting width & height doesn't help at all.

Can you provide the svg ?

Sure I can but in fact is doesn't matter, which svg's to use. If I use Image component for any one of them - it is loading properly.

Princesseuh commented 6 months ago

The SVG in the repro is quite wonky, many tools can't parse it correctly. For instance, trying to paste it in https://jakearchibald.github.io/svgomg/ results in an error about it being invalid.

image-size, the library we use, tries its best to detect that it's a SVG, but it's tough when the SVG is malformed / unusually formed.

Replacing the SVG with a more proper one (a random leaf icon I found online) works: https://stackblitz.com/edit/astro-plbyh1?file=src%2Ffiles%2Fleaf.svg

matthewp commented 6 months ago

Closing as this is an upstream issue.