-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Description
Link to the code that reproduces this issue
https://github.com/niels-bosman/next-server-action-binary-bug-reproduction
To Reproduce
- Clone this repository: https://github.com/niels-bosman/next-server-action-binary-bug-reproduction
- Run
bun install - Go to /
- Refresh and see the dev server crash
Current vs. Expected behavior
When returning binary data from a server action (either by reading a file via fs or fetching binary data from a Prisma database row), the response consistently fails for certain files. The underlying cause within those specific binary files is unclear.
In a minimal reproduction case, the issue occurs when reading a particular file from the filesystem and returning its bytes to the client. Other files work as expected, so the problem seems related to some property of the binary data itself.
Expected behavior:
The server action should successfully return all binary files as byte data without error.
Actual behavior:
For specific binary files, the request fails consistently with the following error in the server logs:
GET / 200 in 63ms
⨯ [Error: failed to pipe response] {
[cause]: [Error: failed to write chunk to response] {
[cause]: TypeError: Cannot perform Construct on a detached ArrayBuffer
at new Uint8Array (<anonymous>)
}
}
⨯ [Error: failed to pipe response] {
page: '/',
[cause]: [Error: failed to write chunk to response] {
[cause]: TypeError: Cannot perform Construct on a detached ArrayBuffer
at new Uint8Array (<anonymous>)
}
}
TypeError: Cannot perform Construct on a detached ArrayBuffer
at new Uint8Array (<anonymous>)
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.0.0: Mon Aug 25 21:17:56 PDT 2025; root:xnu-12377.1.9~3/RELEASE_ARM64_T6030
Available memory (MB): 18432
Available CPU cores: 12
Binaries:
Node: 20.11.0
npm: 10.5.0
Yarn: 1.22.21
pnpm: 8.15.4
Relevant Packages:
next: 15.5.5 // Latest available version is detected (15.5.5).
eslint-config-next: N/A
react: 19.1.0
react-dom: 19.1.0
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Server Actions, Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local), next start (local), Vercel (Deployed)
Additional context
The file is a gzipped version of the JSON file also included In the repository.
The error sometimes happens on Vercel with these error logs:
node:buffer:634
write: (buf, string, offset, len) => buf.utf8Write(string, offset, len),
^
RangeError: "offset" is outside of buffer bounds
at Object.write (node:buffer:634:46)
at fromStringFast (node:buffer:463:22)
at fromString (node:buffer:487:51)
at Function.from (node:buffer:297:12)
at console.<anonymous> (/opt/rust/nodejs.js:6:121)
at process.<anonymous> (/var/task/node_modules/next/dist/compiled/next-server/server.runtime.prod.js:14:40750)
at process.emit (node:events:536:35)
at process._fatalException (node:internal/process/execution:188:25) {
code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}
Node.js v20.19.4