I have a TypeScript Next.js project that has thousands of images in the public folder. Is there any way I can check an existing image before using the <Image /> component in next/image?
I was able to do this using JavaScript only, but TypeScript is too complex. I also get an error returned from Next.js that says:
The requested resource is not a valid image for
/cars/audi-4.jpgreceivedtext/html; charset=utf-8
ImageError: The requested resource is not a valid image.
How to check for existing /cars/audi-4.jpg? I would like to use a default image if it does not exist.
src\app\page.js (Next.js 13 app)
Check the embedded comments for the flow
Folder structure with Public folder and page.js for Next.js 13 app,
I hope this helps