I'm working with next.js and trying to get images dynamically like this:
{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>
))}
With this code I get the following error: "./public/assets/products/Product-One.png 1:0 Module parse failed: Unexpected character '�' (1:0)"
When I hard code the image everything works, f.ex.:
...
<img
src={require(`../public/assets/products/Product-One.png`)}
/>
...
So I suppose that I get the error because of the dynamic variable?! Could someone help me with the issue? Thanks a lot!