Skip to content

ERR_HTTP_HEADERS_SENT when sending FormData #34

@sirchnik

Description

@sirchnik

What version of Elysia is running?

@elysiajs/node 1.2.5(elysia@1.2.12(@sinclair/typebox@0.34.22)(openapi-types@12.1.3)(typescript@5.7.3))(formidable@3.5.2)(ws@8.18.0)

What platform is your computer?

Linux 6.13.1-arch1-1 x86_64 unknown nodejs v23.7.0

What steps can reproduce the bug?

import { Elysia } from 'elysia';
import node from '@elysiajs/node';

export const elysiaApp = new Elysia({
	adapter: node(),
}).patch('/', () => {
	const form = new FormData();
	form.append('name', 'Sancho');
	form.append('alias', 'Don Quixote');
	return form;
});
export type ElysiaApp = typeof elysiaApp;

elysiaApp.listen(3334);
console.log('Server started at http://localhost:3334');

running fetch('localhost:3334/', {method: 'PATCH'})

What is the expected behavior?

With @hono/node-server I get FormData.

What do you see instead?

Server started at http://localhost:3334
node:_http_server:351
    throw new ERR_HTTP_HEADERS_SENT('write');
          ^

Error [ERR_HTTP_HEADERS_SENT]: Cannot write headers after they are sent to the client
    at ServerResponse.writeHead (node:_http_server:351:11)
    at eval (eval at composeErrorHandler (file:///home/nik/Projects/sw/sw-reports/node_modules/.pnpm/elysia@1.2.12_@sinclair+typebox@0.34.22_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/compose.mjs:1441:10), <anonymous>:23:5)
    at eval (eval at composeHandler (file:///home/nik/Projects/sw/sw-reports/node_modules/.pnpm/elysia@1.2.12_@sinclair+typebox@0.34.22_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/compose.mjs:1155:12), <anonymous>:9:8)
    at handle (eval at composeHandler (file:///home/nik/Projects/sw/sw-reports/node_modules/.pnpm/elysia@1.2.12_@sinclair+typebox@0.34.22_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/compose.mjs:1155:12), <anonymous>:9:35)
    at Object.mainHandler (file:///home/nik/Projects/sw/sw-reports/node_modules/.pnpm/elysia@1.2.12_@sinclair+typebox@0.34.22_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/index.mjs:560:57)
    at Server.map (eval at composeGeneralHandler (file:///home/nik/Projects/sw/sw-reports/node_modules/.pnpm/elysia@1.2.12_@sinclair+typebox@0.34.22_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/compose.mjs:1337:10), <anonymous>:21:59)
    at Server.emit (node:events:507:28)
    at parserOnIncoming (node:_http_server:1153:12)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:117:17) {
  code: 'ERR_HTTP_HEADERS_SENT'
}

Additional information

No response

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions