Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

For static responses and onRequest hook usage with set.* work - TypeError: undefined is not an object (evaluating 'c.set') #1128

Open
kravetsone opened this issue Mar 15, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@kravetsone
Copy link
Contributor

What version of Elysia is running?

1.2.25

What platform is your computer?

No response

What steps can reproduce the bug?

import { Elysia } from "elysia";
import { describe, it, expect } from "bun:test";

describe("Elysia issue", () => {
	it("should be a test", async () => {
		const elysia = new Elysia().onRequest(({ set }) => {
			set.headers["x-test"] = "test";
		}).get("/", "Hello World");


		const response = await elysia.handle(new Request("http://localhost/"));
        console.log(response)
		expect(response.status).toBe(200);
	});
});

nativeStaticResponse: false didnt fix it

What is the expected behavior?

No response

What do you see instead?

tests\elysia-issue.test.ts:
3 | ) {
4 | const {handler,handleError,hooks:e, mapResponse,mapCompactResponse,mapEarlyResponse,isNotEmpty,utils:{},error:{InternalServerError,},schema,definitions,ERROR_CODE,ElysiaCustomStatusResponse,}=hooks
5 | const trace=e.trace?.map(x=>typeof x==='function'?x:x.fn)??[]
6 | return function handle(c){try{if(isNotEmpty(c.set.headers)||c.set.status!==200||c.set.redirect||c.set.cookie)return mapResponse(handler.clone(),c.set,c.request)
7 | else return handler.clone()
8 | }catch(error){return(async()=>{const set=c.set
                                              ^
TypeError: undefined is not an object (evaluating 'c.set')
      at <anonymous> (file:///Z:/PROJECTS/ts-backend/OPEN-SOURCE/ELYSIA/elysia-connect-middleware/node_modules/elysia/dist/bun/index.js:8:43)
      at <anonymous> (file:///Z:/PROJECTS/ts-backend/OPEN-SOURCE/ELYSIA/elysia-connect-middleware/node_modules/elysia/dist/bun/index.js:8:60)
      at handle (file:///Z:/PROJECTS/ts-backend/OPEN-SOURCE/ELYSIA/elysia-connect-middleware/node_modules/elysia/dist/bun/index.js:10:35)
      at <anonymous> (Z:\PROJECTS\ts-backend\OPEN-SOURCE\ELYSIA\elysia-connect-middleware\node_modules\elysia\src\index.ts:817:17)
      at map (file:///Z:/PROJECTS/ts-backend/OPEN-SOURCE/ELYSIA/elysia-connect-middleware/node_modules/elysia/dist/bun/index.js:25:65)
      at handle (Z:\PROJECTS\ts-backend\OPEN-SOURCE\ELYSIA\elysia-connect-middleware\node_modules\elysia\src\index.ts:6302:57)
      at <anonymous> (Z:\PROJECTS\ts-backend\OPEN-SOURCE\ELYSIA\elysia-connect-middleware\tests\elysia-issue.test.ts:11:33)
      at <anonymous> (Z:\PROJECTS\ts-backend\OPEN-SOURCE\ELYSIA\elysia-connect-middleware\tests\elysia-issue.test.ts:5:25)

Additional information

No response

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

No response

@kravetsone kravetsone added the bug Something isn't working label Mar 15, 2025
kravetsone added a commit to kravetsone/elysia-connect-middleware that referenced this issue Mar 15, 2025
@kravetsone
Copy link
Contributor Author

this is regression because ^1.1.3 in my tests works fine

But how to fix it? Static responses should not be changed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant