Category: Next.js, React and TypeScript

Next.js Image returns 400 despite the correct image

Read this guide in Polish

The normal image URL works, but the / next/image request ends with HTTP 400. The optimizer checks the source, URL parameters and allowed hosts, so the problem may be different from the lack of the file itself.

How to determine the source of the error

In Network, view URL / next/image, url, w and q, as well as the full content of the error response.

Check the image.remotePatterns configuration and see if the remote server correctly returns Content-Type image.

What to do step by step

1. Match allowed host, protocol and pathname only to trusted source; do not open all domains without need.

2 . If the source blocks an optimizer fetch, configure the correct file access or use unoptimized for the selected graphics.

How to check the score

The graphics are loaded on the phone and desktop, and the optimizer request does not return 400.

What to do

Do not disable host protection on the entire site just to fix a single photo.