In my case, even the optimized (production-like) build had the images working locally, but when I released a Docker container with those images, some ended up corrupted.
The image loaded with an HTTP 200 success status but showed the broken image icon (the one that appears when an image is not found). I entered the container and moved the file to the host, and I couldn’t open the image on the host either.
Some images, for whatever reason, ended up corrupted when moving to the Docker image, or it could be some incompatibility between images in Windows (my host) and Linux. In any case, I saw that when opening the Git repository in VS Code inside WSL2, the image couldn’t be opened.
Deleting the images folder in Linux, and then moving the directory with the images from Explorer in Windows into the Git repo inside WSL2, showed several files as different in the Git diff. I noticed those were the files that couldn’t be opened in Linux. Moving them from Windows to Linux fixed them, and I could open them (the unchanged files were the ones that could already be opened in Linux). Then I did a push in WSL2 and a pull in Windows to update those files. Their data is different, but they show exactly the same in Windows in both cases, and now they also work in Linux and inside the Docker image.
It’s some weird stuff, but this worked for me (at least for my specific problem) and it doesn’t seem to be a Next.js issue.
This isn’t about cases where images fail with 404 or 500 errors. But if your images return a 200 (or 304) status and still fail to display, this might be the cause.
import phone1 from "../public/pictures/icon/iphone/phone1.png"and just usephone1as the src. I hope someone answers with an explanation to why this happens sometimes