cloudflare/vinext

Build: `/_next/image` optimization endpoint returns 400 / `text/html` instead of optimized image

Closed

#1,570 opened on May 22, 2026

 (1 comment) (0 reactions) (1 assignee)TypeScript (371 forks)github user discovery
adapter-api-e2ehelp wanted

Repository metrics

Stars
 (8,563 stars)
PR merge metrics
 (Avg merge 1d 1h) (462 merged PRs in 30d)

Description

Follow-up to #1513 / #1562. The URL prefix rename (/_vinext/image/_next/image) was split into #1562 as a small isolated patch. The remaining part of #1513 needs its own work:

Problem (remaining)

vinext's image optimization endpoint at /_next/image returns 400 with content-type: text/html instead of the optimized image bytes:

Expected content-type: image/png | Received: text/html

Next.js's /_next/image?url=...&w=...&q=...&dpl=... endpoint must respond with the optimized image (or a redirect to one). Two reasonable implementations:

  1. On-the-fly optimization at the worker — port (or adapt) Next.js's image optimization pipeline.
  2. Proxy to Cloudflare Images — let the platform do the resizing.

Reference

  • .nextjs-ref/test/e2e/app-dir/next-image/next-image.test.ts
  • .nextjs-ref/packages/next/src/server/image-optimizer.ts

Estimated impact

~9 e2e test failures remaining after #1562.

Recommendation

  1. Reproduce in vinext's own test suite: hit /_next/image?url=... with a static asset path; assert the response has content-type: image/<format> and a 200 status.
  2. Decide between on-the-fly vs Cloudflare Images proxy (the latter is likely simpler for the Workers runtime).
  3. Implement the endpoint behind the existing IMAGE_OPTIMIZATION_PATH constant.

Part of #1328.

Contributor guide