I hit another Problem with my project that I cannot resolve or understand.
useEffect(() => {
axios.get(API_BASE_URL + '/user/images', payload)
.then(function (response) {
if (response.status >= 200 && response.status < 300) {
console.log("RESPONSE IMAGE:" + JSON.stringify(response.data, null, 2));
let files = response.data.files[0];
const requirestring = "../../images/public/" + files;
let requireimg;
if(files == null){
requireimg = require("../../images/basic-profile-picture.jpg");
}else {
try{
>> requireimg = require(requirestring);
}catch (e){
requireimg = require("../../images/basic-profile-picture.jpg");
}
}
setMapImages(<Image className={"profilepicture"} src={requireimg.default} alt={"TEXT"} />);
} else {
alert("error getting images");
}
})
.catch(function (error) {
console.log("DOWNLOAD: " + error);
});
Why is this part:
requireimg = require(requirestring);
throwing this exception:
Cannot find module '../../images/public/600bc441b2b2b62c542bd135_profilepicture.jpg'
But this works and isnt throwing an exception somehow:
requireimg = require("../../images/public/600bc441b2b2b62c542bd135_profilepicture.jpg")
The exception first occurred when I set the image-name with an "_" for better syntax.