Next.js "Image Optimization requires" - Fix in CI
Next.js image optimization needs a server. With output: 'export', or when a remote image host is not allow-listed, next/image cannot run the optimizer and the build errors.
What this error means
The build fails telling you image optimization requires a loader/host, or that the remote pattern is not configured.
next
Error: Image Optimization using the default loader is not compatible
with `output: 'export'`.
Possible solutions:
- Use `loader: 'custom'` or set `images.unoptimized = true`.Common causes
Static export with default loader
output: 'export' has no server to optimize images, so the default loader is unsupported.
Remote host not allow-listed
A remote src host is not declared under images.remotePatterns, so the optimizer refuses it.
How to fix it
Disable optimization for static export
- Set images.unoptimized when exporting a fully static site.
next.config.js
// next.config.js
module.exports = { output: 'export', images: { unoptimized: true } };Allow-list remote image hosts
- Add the host to remotePatterns so the optimizer accepts it.
next.config.js
// next.config.js
images: { remotePatterns: [{ protocol: 'https', hostname: 'cdn.example.com' }] },How to prevent it
- Decide on static vs server rendering before configuring next/image.
- Keep remotePatterns in sync with the CDNs you actually use.
Related guides
Next.js "Module not found: Can't resolve" - Fix in CIFix "Module not found: Can't resolve" during next build in CI - a missing dependency, a wrong tsconfig path a…
Next.js "Export encountered errors" - Fix in CIFix "Export encountered errors on following paths" in CI - a page threw during static export, often from runt…
Next.js "Invalid next.config.js options" - Fix in CIFix "Invalid next.config.js options detected" in CI - an unrecognized, moved, or wrongly typed config key fai…