Skip to content

Next.js 16.2.6 breaks Nextjs image optimizer for local public images #6867

Description

@dannysteenman

Problem

After upgrading a SST sst.aws.Nextjs site from Next.js 16.2.4 to 16.2.6, optimized images served through /_next/image started returning HTTP 500 in production. The same source images are still reachable directly from the public asset path.

Example behavior:

  • https://example.com/images/landing/services/aws-partner-network-badge.png -> 200
  • https://example.com/_next/image?url=%2Fimages%2Flanding%2Fservices%2Faws-partner-network-badge.png&w=640&q=75 -> 500

Rolling back and pinning next and @next/third-parties to 16.2.4 fixes the issue immediately after redeploy.

Environment

  • SST: 4.13.1
  • Construct: sst.aws.Nextjs
  • Next.js broken version: 16.2.6
  • Next.js working version: 16.2.4
  • Runtime in sst.config.ts: nodejs24.x
  • Image optimization configured:
imageOptimization: {
  memory: '1792 MB',
},
server: {
  architecture: 'arm64',
  memory: '1792 MB',
  runtime: nodeRuntime,
},

Lambda logs

The SST image optimizer Lambda logs this for local public images:

ERROR upstream image response failed for /images/logos/cloudburn.png TypeError: s is not a function
    at Dye (file:///var/task/index.mjs:44:67054)
    at iPe (file:///var/task/index.mjs:102:60148)
    at oPe (file:///var/task/index.mjs:102:60971)
    at BufferedInvokeProcessor.handler (file:///var/task/index.mjs:44:83852)
    at async BufferedInvokeProcessor.processInvoke (file:///var/runtime/index.mjs:1092:22)

ERROR Failed to optimize image Ft [Error]: "url" parameter is valid but upstream response is invalid
    at Dye (file:///var/task/index.mjs:44:68211)
    at iPe (file:///var/task/index.mjs:102:60148)
    at oPe (file:///var/task/index.mjs:102:60971)
    at BufferedInvokeProcessor.handler (file:///var/task/index.mjs:44:83852)
    at async BufferedInvokeProcessor.processInvoke (file:///var/runtime/index.mjs:1092:22) {
  statusCode: 500
}

Likely cause

Next.js changed the internal fetchInternalImage function signature between 16.2.4 and 16.2.6.

In next@16.2.4:

async function fetchInternalImage(href, _req, _res, handleRequest) {

In next@16.2.6:

async function fetchInternalImage(href, _req, _res, maximumResponseBody, handleRequest) {

The error looks consistent with SST/OpenNext still calling the old 4-argument shape. If so, the real handleRequest function is passed as maximumResponseBody, and handleRequest becomes undefined, producing the minified TypeError: s is not a function when the image optimizer tries to fetch a local public image.

Workaround

Pin Next packages to 16.2.4:

{
  "dependencies": {
    "@next/third-parties": "16.2.4",
    "next": "16.2.4"
  }
}

After redeploying with 16.2.4, the /_next/image URLs work again.

Expected behavior

SST's Next.js image optimizer should support the Next.js 16.2.6 internal image optimizer signature, or pin/guard incompatible Next.js versions with a clear error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions