Skip to content

Bug with node adapter and Elysia derive #18

@Manuelbaun

Description

@Manuelbaun

What version of Elysia is running?

1.2.0

What platform is your computer?

Darwin 24.1.0 arm64 arm

What steps can reproduce the bug?

install
@elysiajs/node@1.2.3
node@23.6.0

What is the expected behavior?

accessing the cookie in the derive method should give the cookie,

const app = new Elysia({ adapter: node() })
    .use((app) =>
        app
            .derive({ as: "global" }, async ({ cookie }) => {
                // some inner logic
                return {};
            })
            .onAfterHandle({ as: "global" }, async ({ response }) => {
                console.log("onAfterHandle", response);
                // await commitSession();
                return response;
            }),
    )
    .get("/", () => "Hello World")
    .listen(envs.PORT);

What do you see instead?

I get some error ECONNRESET

node:_http_server:358
    throw new ERR_HTTP_INVALID_STATUS_CODE(originalStatusCode);
          ^

RangeError [ERR_HTTP_INVALID_STATUS_CODE]: Invalid status code: undefined
    at ServerResponse.writeHead (node:_http_server:358:11)
    at eval (eval at composeErrorHandler (/.../node_modules/.pnpm/elysia@1.2.10_@sinclair+typebox@0.34.13_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/cjs/compose.js:1452:10), <anonymous>:23:5)
    at handle (eval at composeHandler (/.../node_modules/.pnpm/elysia@1.2.10_@sinclair+typebox@0.34.13_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/cjs/compose.js:1165:12), <anonymous>:16:8)
    at Object.mainHandler (/.../node_modules/.pnpm/elysia@1.2.10_@sinclair+typebox@0.34.13_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/cjs/index.js:589:102)
    at Server.map (eval at composeGeneralHandler (/.../node_modules/.pnpm/elysia@1.2.10_@sinclair+typebox@0.34.13_openapi-types@12.1.3_typescript@5.7.3/node_modules/elysia/dist/cjs/compose.js:1347:10), <anonymous>:22:57)
    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_INVALID_STATUS_CODE'
}

Additional information

this works:

const app = new Elysia({ adapter: node() })
    .use((app) =>
        app
            .derive({ as: "global" }, async ({ cookie }) => {
                // some inner logic
                return {};
            })
            .onAfterHandle({ as: "global" }, async ({ response }) => {
                console.log("onAfterHandle", response);
                // await commitSession();
                return response;
            }),
    )
    .get("/", () => "Hello World")
    .listen(envs.PORT);

Not sure, it it is related to the node adapter, but with the regular adapter with bun, it works.

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

No response

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