0

So I am trying to load the image that the user saved for his/her profile. Trying to use this piece of code:

const imgUrl = '../../styles/img/profpic.png';
const profImg = require(`${imgUrl}`);

And then load the image in the render method as follows:

<img src={profImg} className="" alt={key + " profile pic"} />

When not using backticks, and putting the string in the require brackets, it does find the file within the require call and everything runs ok and loads the image. When using the backticks I get the following error:

Uncaught Error: Cannot find module '../../styles/img/profpic.png'.

Any idea why this is happening?

0 Answers0