astro-imagetools icon indicating copy to clipboard operation
astro-imagetools copied to clipboard

Is dynamic import even possible?

Open MelleNi opened this issue 1 year ago • 3 comments

I'm trying to dynamically import images, like so:

const imageUrl = (await import(src)).default where src is ../images/image.jpg

But I get a svite error:

The above dynamic import cannot be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment inside the import() call to suppress this warning.

Coupled with:

  props.src = props.src.replace(search, "");

Even when I try this:

import imageUrl from "../images/image.jpg";

I get an error:

TypeError: props.src.replace is not a function
    at Module.getFilteredProps 

How do I dynamically import images?

MelleNi avatar Jun 07 '23 11:06 MelleNi