In the Next.js 15.1.6 docs (App Router), the last code snippet on the Metadata Files: opengraph-image and twitter-image | Next.js page explains how to fetch a local image on the file system and pass it as an ArrayBuffer to the src attribute of an <img> element in order to programmatically generate an OpenGraph image (very useful for dynamic route segments).
Here is the snippet:
app/opengraph-image.tsx:
import { ImageResponse } from 'next/og'
import { join } from 'node:path'
import { readFile } from 'node:fs/promises'
export default async function Image() {
const logoData = await readFile(join(process.cwd(), 'logo.png'))
const logoSrc = Uint8Array.from(logoData).buffer
return new ImageResponse(
(
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<img src={logoSrc} height="100" />
</div>
)
)
}
When I copy and paste this snippet into a new Next.js 15 project (create-next-app@latest), I get a type error saying:
Type 'ArrayBuffer' is not assignable to type 'string'.ts(2322)
index.d.ts(3051, 9): The expected type comes from property 'src' which is declared here on type 'DetailedHTMLProps<ImgHTMLAttributes, HTMLImageElement>'
⚠ Error (TS2322) | Type
ArrayBufferis not assignable to typestring.(property) ImgHTMLAttributes.src?: string | undefined
Are the docs wrong?
Here is a reproduction repository: https://github.com/shawninder/opengraph-type-error-repro
You can see the type error by opening src/app/opengraph-image.tsx in a Typescript-enabled editor or by running npm run build