-
Notifications
You must be signed in to change notification settings - Fork 27.4k
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
Docs: Make it clear that next/image is not compatible with SSG (next export) and improve the related docs #36431
Comments
That isn't necessarily true, I think it would be possible to create every variation of the optimized image at build-time. This solution wouldn't support dynamic domains or URLs, just static imports (which isn't always the case and likely why the team decided not to implement it this way) |
There's an article here that shows how you can go about setting a custom loader and other alternatives too |
I don't want to put all my website's images put on a third party cloud provider, I need control of hosting and would like to just export a complete static website to host myself. This is especially true for anyone working on internal webapps which may include sensitive data. Aside from cloud hosting, this article gives the same solution I mentioned in my OP - fiddle with config or custom loaders in order to opt out of image optimization so SSG will actually work. My request with this issue is that this requirement is made clear in the NextJS documentation not just external blogs and GitHub discussions.
Yes there is discussion of this and other possible ways to fix image optimization for SSG, but in the mean time my hope with this issue is to update the current documentation so that people understand this is currently not possible and can know what is needed to fix My understanding is users need to do at least one of these things before they can run
This is pretty simple when listed out, but as a new user took me many hours reading blogs and issues to understand what my options were, when all I wanted to do was export and serve a static HTML website. Many of those solutions also require refactoring code which wouldn't have been needed if I understood this ahead of time |
Oh oh! That's fine then 😎 |
Any update about this issue with the 13 release ? |
I was having similar issues, so I just disabled the image optimization in the next configuration file. |
100% agree with you! |
It is possible to use Image Optimization through /** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
images: {
loader: 'custom',
loaderFile: './app/image.ts',
},
}
module.exports = nextConfig This custom loader will define how to fetch images from a remote source. For example, the following loader will construct the URL for Cloudinary: export default function cloudinaryLoader({
src,
width,
quality,
}: {
src: string
width: number
quality?: number
}) {
const params = ['f_auto', 'c_limit', `w_${width}`, `q_${quality || 'auto'}`]
return `https://res.cloudinary.com/demo/image/upload/${params.join(
','
)}${src}`
} You can then use import Image from 'next/image'
export default function Page() {
return <Image alt="turtles" src="/turtles.jpg" width={300} height={300} />
} Source: https://nextjs.org/docs/app/building-your-application/deploying/static-exports#image-optimization |
To discuss optimizing images during static export builds, please see this feature request: #19065 |
What is the improvement or update you wish to see?
There is no mention in the NextJS image documentation that
next/image
does not work withnext export
.It should be mentioned on these pages:
https://nextjs.org/docs/basic-features/image-optimization (main
next/image
docs)https://nextjs.org/docs/messages/no-img-element (error page you're directed to when not using
next/image
)This issue is just about improving the docs, but also there really should be improvements to the default config so that users can use images on their SSG site without having to follow docs to apply workarounds
Is there any context that might help us understand?
This has been my experience as a new NextJS user this week:
create-next-app
and design all my pages (with images)@next/next/no-img-element
ESLint warnings telling me to usenext/image
next/image
(including fixing some broken CSS since it's actually animg
inside adiv
not a direct image replacement)img
components... only to find this doesn't work either - on build I get a bunch of errors from the various image packages like this and I didn't want to spend more time debugging dependencies of a dependency that is already an unoffocial workaround.I decided to use NextJS over CRA even though I don't need SSR because I saw people touting it as having a better DX and sane defaults, but that doesn't feel true at all for SSG so far
There are many highly upvoted comments requesting similar improvement to the documentation and saying it's misleading to market NextJS as an SSG in its current state (#18356 (comment), #19065 (comment), #19065 (comment), #19065 (comment), #19065 (comment))
Does the docs page already exist? Please link to it.
https://nextjs.org/docs/basic-features/image-optimization
DX-1662
The text was updated successfully, but these errors were encountered: