Open
Description
💬 Change introduced in v5.0.0-alpha.4 is crashing my application
In fastify/lib/reply.js
this part was removed:
// Response
if (isResponse) {
// https://developer.mozilla.org/en-US/docs/Web/API/Response/headers
if (typeof payload.headers === 'object' && typeof payload.headers.forEach === 'function') {
for (const [headerName, headerValue] of payload.headers) {
reply.header(headerName, headerValue)
}
}
// https://developer.mozilla.org/en-US/docs/Web/API/Response/body
if (payload.body != null) {
if (payload.bodyUsed) {
throw new FST_ERR_REP_RESPONSE_BODY_CONSUMED()
}
// Response.body always a ReadableStream
sendWebStream(payload.body, res, reply)
}
return
}
Instead of the above, the process is running into
if (typeof payload !== 'string' && !Buffer.isBuffer(payload)) {
throw new FST_ERR_REP_INVALID_PAYLOAD_TYPE(typeof payload)
}
I failed to find documentation regarding this breaking change in the migration documentations. Maybe I am missing something?
https://fastify.dev/docs/v5.0.x/Guides/Migration-Guide-V5/
https://fastify.dev/docs/v5.1.x/Guides/Migration-Guide-V5/
/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:642
throw new FST_ERR_REP_INVALID_PAYLOAD_TYPE(typeof payload)
^
FastifyError [Error]: Attempted to send payload of invalid type 'object'. Expected a string or Buffer.
at onSendEnd (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:642:11)
at wrapOnSendEnd (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/reply.js:536:5)
at next (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/hooks.js:289:7)
at handleResolve (/path-to-project/node_modules/.pnpm/[email protected]/node_modules/fastify/lib/hooks.js:306:5)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'FST_ERR_REP_INVALID_PAYLOAD_TYPE',
statusCode: 500
}
Node.js v20.16.0
[nodemon] app crashed - waiting for file changes before starting...
Environment
- node version: 20
- fastify version: >=v5.0.0-alpha.4
- os: Mac, Linux