If we run the file on the system, there is no issue but when we deploy it on Heroku and try to remove the image after uploading, an error popup is shown.

Try it yourself here - https://kanakmi-dogvscat.herokuapp.com/
I have actually resolved this issue, please assign it to me so that I can change it here as well.
The website with the removed issue can be found here - https://animevscartoon.herokuapp.com/