#43996·bun

`Bun.write` stringifies input it does not support, so `Bun.write(path, img.png())` writes "[object Image]" and reports success

Author: oddharshCreated Sep 25, 2026Updated Sep 28, 2026
Labelsbugruntime

What version of Bun is running?

1.4.3-canary.1+09bb54630

What platform is your computer?

Darwin 27.2.0 arm64

What steps can reproduce the bug?

typescript
// 1x1 RGBA PNG, so the repro needs no files on disk.
const png = Uint8Array.fromBase64(
  "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR4nGP4z8DwHwAFAAH/iZk9HQAAAABJRU5ErkJggg==",
);
const img = new Bun.Image(png);

const n = await Bun.write("out.png", img.png());
console.log(n, await Bun.file("out.png").text()); // 14 "[object Image]"

The same thing happens for any object Bun.write doesn't recognise:

call returns file contents
Bun.write(path, img.png()) 14 [object Image]
Bun.write(path, img) 14 [object Image]
Bun.write(path, {}) 15 [object Object]
Bun.write(path, new Response(img.png())) 70 the PNG
img.png().write(path) 70 the PNG
Bun.write(path, await img.png().blob()) 70 the PNG

What is the expected behavior?

A TypeError for input Bun.write can't write. bun-types already rejects the call (TS2769: No overload matches this call on Bun.write("a.png", img.png())), and Node's fs.writeFile(path, {}) throws ERR_INVALID_ARG_TYPE.

Separately, it might be worth accepting Bun.Image directly. docs/runtime/image.mdx says new Response(img) works and that .write() takes "the same destinations as Bun.write", so reaching for Bun.write(path, img.png()) is a natural guess.

What do you see instead?

The object is coerced with String(), the 14-byte string is written, and the promise resolves with 14. Nothing fails, so the bad file only turns up when something tries to decode it.

Additional information

I ran into this in a JavaScript script, where the types can't catch it. img.png() reads like it returns encoded bytes, and it actually returns the Image with its output format set.

I used an AI assistant (Claude) to reduce this to a minimal repro and draft the issue. I ran the snippet and checked every row of the table myself.