taxonomy icon indicating copy to clipboard operation
taxonomy copied to clipboard

Type error: Route "app/api/og/route.tsx" has an invalid export

Open pwnllc opened this issue 1 year ago • 6 comments

Hello! When I try to build this on my RPi, the following error occurs:

app/api/og/route.tsx
Type error: Route "app/api/og/route.tsx" has an invalid export:
  "Promise<ImageResponse>" is not a valid GET return type:
    Expected "void | Response | Promise<void | Response>", got "Promise<ImageResponse>".
      Expected "Promise<void | Response>", got "Promise<ImageResponse>".
        Expected "void | Response", got "ImageResponse".

pwnllc avatar Oct 23 '23 14:10 pwnllc

Same problem here. Any solution so far?

SaadBazaz avatar Nov 24 '23 04:11 SaadBazaz

I have solved this by moving the og API from app/api/og/route.ts to pages/api/og.ts. This seemed the easiest and most stable solution to me

fardeenes7 avatar Nov 27 '23 07:11 fardeenes7

Is there any other solutions so far?

elickeenanjones avatar Jan 26 '24 16:01 elickeenanjones

I have solved this by moving the og API from app/api/og/route.ts to pages/api/og.ts. This seemed the easiest and most stable solution to me

This worked for me after cracking my head around for days. There isn't any solution around on why Next 14 does not support ImageResponse as a response in an api route under the app router.

jiaweing avatar Feb 05 '24 02:02 jiaweing

I also tried the opengraph-image.tsx method but there isn't any way to pass in any parameters other than only using those from the url. https://nextjs.org/docs/app/building-your-application/optimizing/metadata#dynamic-image-generation

jiaweing avatar Feb 05 '24 02:02 jiaweing

Change the import to: import { ImageResponse } from "next/og"

tknickman avatar Mar 30 '24 14:03 tknickman