Skip to content

Is dynamic import even possible? #168

Description

@MelleNi

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions