.wrap() JSDoc example drops the server argument, so context.server is null
What version of Elysia is running?
What platform is your computer?
Darwin 24.6.0 arm64 arm
What environment are you using
Bun 1.4.2
Are you using dynamic mode?
No
What steps can reproduce the bug?
A .wrap() written like the example in its JSDoc ((fetch) => (request) => fetch(request)) makes context.server null for every request:
import { Elysia } from 'elysia'
const app = new Elysia()
// Same shape as the example in the .wrap() JSDoc
.wrap((fetch) => (request) => fetch(request))
.get('/', ({ server, request }) => ({
server: server === null ? null : 'set',
ip: server?.requestIP(request)?.address ?? null
}))
.listen(0)
console.log(await fetch(app.server!.url).then((response) => response.text())) await app.stop()
What is the expected behavior?
server is the running Bun server and server.requestIP(request) returns the client address, as it does without .wrap():
{"server":"set","ip":"::1"}
What do you see instead?
{"server":null,"ip":null}
Additional information
Bun passes the server as the second argument to fetch, and the compiled handler assigns context.server = server ?? null. The WrapFn type does declare ...rest, and the Bun adapter's own internal wrapper forwards (request, server), but the public .wrap() example drops it. Forwarding the rest arguments fixes it:
.wrap((fetch) => (request, ...rest) => fetch(request, ...rest)) Possible fixes:
update the .wrap() JSDoc example (and the website docs, if they use the same snippet) to forward ...rest; and/or fall back to the server started by listen() when the argument is missing, so a wrapper cannot silently lose it.
Have you try removing the node_modules and bun.lock and try again yet?
Yes, reproduced in a fresh project.
Source: elysiajs/elysia