Skip to content

"Response body object should not be disturbed or locked" using body destructuring assignment in derive({ body }) #31

@ggondim

Description

@ggondim

What version of Elysia is running?

1.2.10

What platform is your computer?

Darwin 24.3.0 arm64 arm

What steps can reproduce the bug?

  1. Create an Elysia server using Node adapter with a derive and a post. Use destructuring assignment with the body property from the Context.
import { node } from '@elysiajs/node';
import { Elysia } from 'elysia';

const app = new Elysia({ adapter: node() })
  .onError(({ error }) => {
    return error;
  })
  .derive(({ body }) => {
    return {
      operation: 'test'
    };
  })
  .post(`/bug`, ({ operation }) => {
    return operation;
  })
  .listen(3777);
  1. Run the server with Node.js and make an HTTP request to POST /bug.

What is the expected behavior?

The expected behavior is to return "test' in the HTTP response, using the code above.

What do you see instead?

The onError handler will be caught with the error "Response body object should not be disturbed or locked".

Additional information

If you remove the destructuring assignment, the server responds normally.

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

const app = new Elysia({ adapter: node() })
  .onError(({ error }) => {
    return error;
  })
  .derive((context) => {
    return {
      operation: 'test',
      body2: context.body,
    };
  })
  .post(`/bug`, ({ operation }) => {
    return operation;
  })
  .listen(3777);

⚠ The body destructuring assignment is working normally running with Bun and without the Node adapter.

💡 Digging on the Web, I found this could be probably related to Fetch's Request body cloning. The destructuring assignment could be cloning the Request body without the proper .clone() call.

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

Sure.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions