Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized images not found because theyre not in root #78

Closed
kevincarld opened this issue Dec 2, 2022 · 10 comments · Fixed by #88
Closed

Optimized images not found because theyre not in root #78

kevincarld opened this issue Dec 2, 2022 · 10 comments · Fixed by #88

Comments

@kevincarld
Copy link

Hi,
Im using next export and the images are not found, How do I make it such that the beginning path of images has "./" instead of "/".

Thanks

@Niels-IO
Copy link
Owner

Niels-IO commented Dec 2, 2022

Hi @kevincarld,

Could you please explain the use case of "./" instead of "/" to me? Can you share an example of how you are using the ExportedImage component?

@kevincarld
Copy link
Author

Hi @Niels-IO , actually I think I just have the same issue as the other comments. Because the static site im exporting won't be in the root directory that's why image src's are having issue

@Niels-IO Niels-IO linked a pull request Dec 9, 2022 that will close this issue
@Rashair
Copy link

Rashair commented Dec 11, 2022

Can this be reopened? My images are not found after proper export:

Code:

  import logo from "public/images/logo.png";
...
 <ExportedImage src={logo} style={{height: "100%", width: "auto"}}
                             alt="Faces in front of each other"/>
package.json
"build:docker": "next build && next export -o .export && next-image-export-optimizer --exportFolderPath .export",

DockerFile:
WORKDIR /app/clientApp
COPY --from=builder /opt/app/.export ./

Container:
image

The app:
image
image

It seems like the path should be under images?

@Rashair
Copy link

Rashair commented Dec 11, 2022

Actually, the name is wrong:
Should be logo-opt-10.WEBP
Not logo.bc950706-opt-10.WEBP
Any idea why this random identified is added?

@Niels-IO Niels-IO reopened this Dec 12, 2022
@Niels-IO
Copy link
Owner

Hi @Rashair,

After you run the command "build:docker", you should see a folder called nextImageExportOptimizer inside the .export folder. (I confirmed with the example app in this module that this is correctly working).

Then the URL in the browser would resolve as the images are stored in the nextImageExportOptimizer folder, which is indeed at the root level. The random hash is actually created by next.js as you have used statically imported images, and this is how they handle it. As the srcset uses the images with the added hash and the images in the folder nextImageExportOptimizer are named accordingly, everything matches.

Where are the optimized images placed if you run the build:docker command?

@Rashair
Copy link

Rashair commented Dec 12, 2022

There only under 'images' - nowhere else. The nextImageExportOptimizer folder does not appear. I've also tried on your example app and it works locally for me there, but not in my own app :/

@Rashair
Copy link

Rashair commented Dec 17, 2022

I think the issue is with the statically imported images - other seem to work

@Niels-IO
Copy link
Owner

Hi @Rashair,

I am currently a little bit clueless about how to help you further. Could you create a minimal example that reproduces the error?

@Rashair
Copy link

Rashair commented Dec 18, 2022

I think I found the issue - I have a custom distDir, it's .build, not .next.
Here's a reproduction using your example:
https://github.com/Rashair/next-image-export-optimizer-78
(The reproduction only works on the clean repo - if you don't have .next dir there, otherwise it will supposedly copied from there)

@Niels-IO
Copy link
Owner

Hi @Rashair,

Thank you very much! This is indeed the issue, and I found an easy fix. I will release it in the next patch version.

@Niels-IO Niels-IO linked a pull request Dec 18, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants