Currently, I am utilizing next.js and attempting to dynamically retrieve images in the following manner:
{list.map((prod) => (
<div className={styles.singleProduct}>
<h6>{prod.Brand.toUpperCase()}</h6>
<p>{prod.ProductName}</p>
<img
src={require(`../public/assets/products/${prod.ProductName
.replace(" ", "-")}.png`)}
/>
</div>
))}
Unfortunately, when implementing this code, I encounter the following error message: "./public/assets/products/Product-One.png 1:0 Module parse failed: Unexpected character '' (1:0)"
In contrast, manually inputting the image path resolves any issues. For example:
...
<img
src={require(`../public/assets/products/Product-One.png`)}
/>
...
I suspect that the error arises due to the dynamic variable. Any assistance in resolving this matter would be greatly appreciated. Thank you!