`.compile()` throws on any route with a schema: `this.tb.buildResult.external` is undefined (2.0.0-beta.14)
What version of Elysia is running?
[email protected] (with [email protected] and [email protected])
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?
import { Elysia, t } from "elysia";
new Elysia()
.get("/n/:id", { params: t.Object({ id: t.Numeric() }) }, ({ params }) => params)
.compile();The same happens with a query, body, or headers schema, including a plain t.Object({ n: t.String() }).
What is the expected behavior?
.compile() precompiles the route, as it does for routes without schemas.
What do you see instead?
error: [Elysia] Failed to compile route GET /n/:id: undefined is not an object (evaluating 'this.tb.buildResult.external')
at new TypeBoxValidator (dist/type/validator/index.mjs:281:28)Additional information
With precompile, TypeBoxValidator builds the validator eagerly and reads this.tb.buildResult.external.variables (src/type/validator/index.ts:616 at b51e5d8). this.tb comes from SchemaCompile, which type/typebox-value.ts maps to typebox/schema's Compile. In [email protected], and on TypeBox main, that returns a Validator without a buildResult property.
Without .compile() the validator is deferred, and app.handle() and app.listen() validate the same routes correctly.
Source: elysiajs/elysia