As of now, I am developing a NextJS application that will eventually be deployed with multiple domains on Vercel. One of the key features of my application is the dynamic rendering of images. While all images display correctly in the preview environment on Vercel, upon deployment to the production environment, I encounter an issue with optimized image responses:
When attempting to load the optimized image, I receive the following error message: Bad request INVALID_IMAGE_OPTIMIZE_REQUEST
Interestingly, if I request the original (unoptimized) image, everything functions as intended. It's worth noting that I am utilizing the latest version of NextJS (14.0.4).
In an effort to troubleshoot this issue, I've experimented with various configurations for NextJS (config.nextjs.mjs), and have also made manual requests for different images (both original and optimized).
Here is a snippet from my current next.config.mjs file:
images: {
dangerouslyAllowSVG: true,
remotePatterns: [
{
hostname: 'domain1.example.com',
},
{
hostname: 'domain2.example.com',
},
],
},
For example, my image URL follows this format: /api/images/some-image-uuid. To render optimized images, I make use of the Image component from next/image.