`response.headers.toJSON is not a function` when trying to return `new Response("foo")` with serverTIming plugin enabled
Closed this issue · 3 comments
With elysia-polyfills@0.6.1 when trying to return any kind of raw response (including the swagger plugin that returns a raw response for the swagger page), as long as the server timing plugin is enabled, it will return the following error:
error: TypeError: response.headers.toJSON is not a function
at mapResponse (/Users/blucky/git/work-sst/node_modules/.pnpm/elysia@0.8.5_@sinclair+typebox@0.32.5_typescript@5.3.3/node_modules/elysia/dist/cjs/handler.js:134:52)
at handle (eval at composeHandler (/Users/blucky/git/work-sst/node_modules/.pnpm/elysia@0.8.5_@sinclair+typebox@0.32.5_typescript@5.3.3/node_modules/elysia/dist/cjs/compose.js:1151:27), <anonymous>:85:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Server.handler (file:///Users/blucky/git/work-sst/node_modules/.pnpm/@bogeychan+elysia-polyfills@0.6.1_elysia@0.8.5/node_modules/@bogeychan/elysia-polyfills/dist/mjs/env/node/server.js:34:35)
disabling the plugin makes it work properly
I know the server timing plugin isn't even on the chart in the README.md
, but this seems like an easy enough fix potentially, just putting a .toJSON = (self)=>JSON.stringify(self)
or something in the right place, so I figured I'd report it anyway
Can you provide more details pls?
- small code snipped to reproduce this + which URL to open
- the versions of
@elysiajs/swagger
,@elysiajs/server-timing
andelysia
This worked for me:
// index.mjs
import '@bogeychan/elysia-polyfills/node/index.js';
import { Elysia } from 'elysia';
import { swagger } from '@elysiajs/swagger';
import { serverTiming } from '@elysiajs/server-timing';
const app = new Elysia()
.use(swagger())
.use(serverTiming())
.get('/', () => ({ hello: 'Node.js👋' }))
.listen({ port: 8080 });
// package.json
{
"dependencies": {
"@bogeychan/elysia-polyfills": "0.6.1",
"@elysiajs/server-timing": "^0.8.0",
"@elysiajs/swagger": "^0.8.0",
"elysia": "^0.8.8"
}
}
node ./index.mjs
- open http://localhost:8080/swagger in browser → no error in console
Should be fixed with 0.6.3
. Let me know if the issue persists
That fixed it, thanks a lot.
It also happened to fix the issue where returning a raw response from the handler kept resulting in the body being {}
. I spent the whole night yesterday on that issue, thanks a lot