My TypeScript Next.js project contains a large number of images in the public folder. I am wondering if there is a way to verify the existence of an image before utilizing the <Image />
component from next/image
.
I have managed to achieve this using plain JavaScript, but TypeScript presents some complexities. Moreover, I encountered an error message from Next.js stating:
The requested resource is not a valid image for
/cars/audi-4.jpg
receivedtext/html; charset=utf-8
ImageError: The requested resource is not a valid image.
Is there a way to determine whether /cars/audi-4.jpg
exists? If not, I would like to utilize a default image instead.