Reputation: 1
I wrote an application by nextjs and I wanted to deploy it somewhere to show others what I made. I chose github pages.
I tried to deploy it as I've learned from a couple of blog posts and used github action with the nextjs profile that github provides.
The .yml file that github has created for me, configures my next js application to set the basePath, assetPrefix and also image optimization, therefore I didn't configure anything myself.
Now that I've deployed my app on github pages, I can't see my images.
My repo name is "ecommerce-product-page".
When I inspected my requests to see why I couldn't see the images, I noticed the images addresses are uncompleted, like :
https://borzoomv.github.io/images/image-product-1.jpg
but it should be:
https://borzoomv.github.io/ecommerce-product-page/images/image-product-1.jpg
The second url is valid, unlike the other one I won't get 404 and the image will be loaded.
I tried to enter my basePath and assetPrefix manually and set them to /ecommerce-product-page, but nothing changed.
I also tried another .yml file I found on a blog post but it also didn't help.
I tried to change the import statements inside my app and omit the public at the beginning of the import addressees but it also didn't help.
Now my image import statements are like this:
import sampleImage from '/public/images/sampleImage.jpg'
and when I omit the public from the beginning, I get build error.
Upvotes: 0
Views: 1761
Reputation: 69
This is a good article talking about the same issue:
https://xerosource.com/nextjs-images-are-not-loading-in-production/
If that doesn't work then a temporary solution is to use unoptimized
<Image src={sampleImage} unoptimized />
Upvotes: 0