Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type 'ArrayBuffer' is not assignable to type 'string'. when using local image. #606

Open
adriangalilea opened this issue Mar 29, 2024 · 1 comment

Comments

@adriangalilea
Copy link

adriangalilea commented Mar 29, 2024

Bug report

Following the example to use a local file I get:

Type 'ArrayBuffer' is not assignable to type 'string'.ts(2322)
index.d.ts(2869, 9): The expected type comes from property 'src' which is declared here on type 'DetailedHTMLProps<ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>'

Seems to work fine tho

Reproduction

Following the guide using local images

export async function GET(request: Request) {
  const imageData = await fetch(
    new URL("./logo-black.png", import.meta.url),
  ).then((res) => res.arrayBuffer());

  return new ImageResponse(
    (
      <div
        style={{
          display: "flex",
          background: "#f6f6f6",
          width: "100%",
          height: "100%",
          flexDirection: "column",
          justifyContent: "center",
          alignItems: "center",
        }}
      >
        <img width="256" height="256" src={imageData} />
      </div>
    ),
    {
      width: 1200,
      height: 630,
    },
  );
  
}

Additional Context

Latest next.js version and og/image

@souporserious
Copy link

souporserious commented Apr 10, 2024

I tried overriding the global JSX namespace to add the ArrayBuffer type, but couldn't get it to work. It's a little more verbose, but you can base64 it to turn it into a string to get around this type error:

<img
  width="256"
  height="256"
  src={`data:image/png;base64,${Buffer.from(imageData).toString('base64')}`}
/>

Not ideal, but alternatively you can use any:

<img src={imageData as any} />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants