-
Notifications
You must be signed in to change notification settings - Fork 44
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
Is dynamic import even possible? #168
Comments
Create a helper function to handle the dynamic import and return the image URL as a string: Call the helper function and pass the image source as a parameter: or use |
When I call it normally, it works, but for some reason only with
But when I try your method, or
I get the error: Edit: maybe noteworthy that I don't get the original error from my first post any longer |
Opph - I've just run into this trying to render an image from However, we can rely on ---
import yourImage from '../images/your-image.jpg'
const src = decodeURIComponent(yourImage.src)
.replace(/.*\/src\//, './src/') // remove root path
.replace(/\?.*$/, '') // remove prams
---
<>
<Img src={src} width="200" alt="test" />
</> |
I'm trying to dynamically import images, like so:
const imageUrl = (await import(src)).default
wheresrc
is../images/image.jpg
But I get a svite error:
Coupled with:
Even when I try this:
import imageUrl from "../images/image.jpg";
I get an error:
How do I dynamically import images?
The text was updated successfully, but these errors were encountered: