-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
astro dev
& astro build
crash with Unknown file extension ".svg"
when importing an SVG inside a dependency
#12299
Comments
This feels like an issue with how you set up your monorepo, I am not sure this is an Astro issue. As you said, using |
When you're linking or copying the library locally, you're doing the inverse of https://vite.dev/guide/dep-pre-bundling.html#monorepos-and-linked-dependencies. The issue here is that since the component library uses bundler specific features, like importing SVGs, that library needs to be processed by the bundler. By default, that does not happen as most libraries are generic and work everywhere, however to opt-in a library to be processed by the bundler, you can configure |
@ematipico I don't think it's a monorepo issue. The issue shows up when I install the library from a tarball, not from the monorepo / a relative path. Besides, my actual setup is not a monorepo in the first place. I just put every together in a single repo for the purposes of providing a reproducing example. |
Yes, that was a conscious decision because all our downstream projects use Vite. And in a pure Vite project it does work, it's only in Astro projects (and only in the dev server) where it's failing. In any case, thanks for your suggestions! I will give them a try! That being said, can you make sense of the fact that everything works fine in a regular Vite/Vue project and also in an Astro/Vite/Vue production build but not in the Astro dev server? |
Following up on this, it seems adding the library to the downstream project's |
With Astro, both dev and build didn't work for me without For plain Vite, it works because you'd eventually bundle everything for the browser, so SVG imports get transformed on the way during build. In dev, usually you have to specify |
I don't think there's a fix possible in Astro for this, so I'll close this for now. But feel free to continue the discussion here if you have any questions. |
I checked again and, yeah, you're right – the behavior is indeed consistent!
I'm not sure I fully understand but given that the Vite docs are very clear about the fact that I should set |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
/
Describe the Bug
I have a Vue component library in which some components
import
SVG files as?url
, so that they can be used inside e.g.<svg><use href="…" /></svg>
. In that library, as a workaround for vitejs/vite#3295 and vitejs/vite#4454, I have manually configured Vite to emit the SVGs as standalone asset files and preserve the?url
imports inside the emitted.js
files.My Astro project depends on that library. But when I import one of those components that import an SVG,
astro dev
andastro build
fail withInterestingly, this error does not occur if I
pnpm link
the library into my Astro project (as opposed to installing the tarball or literally copying the library folder into my Astro project'snode_modules
).What's the expected result?
The SVG import should work as expected. Notably, it works fine if I use a pure Vite dev server
without
Astro, see/consumer
in the repo linked below. Moreover, in my real-life Astro project things worked fine when I didn't transpile the library components to JS first and instead exposed the raw Vue components and imported them in my Astro project. (However, this is not an option for us for various reasons.)Link to Minimal Reproducible Example
https://github.com/codethief/vitejs-vue-component-library-with-assets/tree/7e12eb72ef59036992976cf892f0fda583f141a0?tab=readme-ov-file#caveat-in-astro-consumer
Impact
We have dozens of SVGs in our library and cannot possibly inline them in our Vue components because
id
attributes, so using (inlining) the same SVG twice on the same page will produce ID collisions which has led to hard-to-track-down bugs in the past.In other words: For us there is simply no way around keeping SVGs in separate asset files. The present bug currently prevents this from working, unfortunately. If anyone happens to have a workaround, please let me know!
Participation
The text was updated successfully, but these errors were encountered: