Getting SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'validate')

When I build my express js app using better auth, this is what I get whenever an auth function/endpoint is called. How can I fix this?
SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'validate')
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at runValidation (file:///app/node_modules/better-call/dist/index.js:218:53)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at createInternalContext (file:///app/node_modules/better-call/dist/index.js:407:33)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at internalHandler (file:///app/node_modules/better-call/dist/index.js:564:35)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at api.<computed> (file:///app/node_modules/better-auth/dist/api/index.mjs:480:28)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at async processRequest (file:///app/node_modules/better-call/dist/index.js:4856:24)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at async handler (file:///app/node_modules/better-call/dist/index.js:4876:19)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at async file:///app/node_modules/better-call/dist/node.js:138:22
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info]# SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'validate')
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at runValidation (file:///app/node_modules/better-call/dist/index.js:218:53)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at createInternalContext (file:///app/node_modules/better-call/dist/index.js:407:33)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at internalHandler
SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'validate')
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at runValidation (file:///app/node_modules/better-call/dist/index.js:218:53)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at createInternalContext (file:///app/node_modules/better-call/dist/index.js:407:33)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at internalHandler (file:///app/node_modules/better-call/dist/index.js:564:35)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at api.<computed> (file:///app/node_modules/better-auth/dist/api/index.mjs:480:28)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at async processRequest (file:///app/node_modules/better-call/dist/index.js:4856:24)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at async handler (file:///app/node_modules/better-call/dist/index.js:4876:19)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at async file:///app/node_modules/better-call/dist/node.js:138:22
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info]# SERVER_ERROR: TypeError: Cannot read properties of undefined (reading 'validate')
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at runValidation (file:///app/node_modules/better-call/dist/index.js:218:53)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at createInternalContext (file:///app/node_modules/better-call/dist/index.js:407:33)
2025-04-10T06:18:42Z app[d8d9e10b050778] bom [info] at internalHandler
2 Replies
ultrakiller
ultrakillerOP2w ago
Happens here:
if (options.query) {
const result = await options.query["~standard"].validate(context.query);
if (result.issues) {
return {
data: null,
error: fromError(result.issues, "query")
};
}
request.query = result.value;
}
if (options.query) {
const result = await options.query["~standard"].validate(context.query);
if (result.issues) {
return {
data: null,
error: fromError(result.issues, "query")
};
}
request.query = result.value;
}
in better-call package I also get this error in the better-auth server config:
The types of 'options.body' are incompatible between these types.
Property '"~standard"' is missing in type 'ZodObject<{ email: ZodString; type: ZodEnum<["email-verification", "sign-in", "forget-password"]>; }, "strip", ZodTypeAny, { email: string; type: "sign-in" | "email-verification" | "forget-password"; }, { email: string; type: "sign-in" | "email-verification" | "forget-password"; }>' but required in type 'StandardSchemaV1<unknown, unknown>'.ts(2322)
router-DQIhoWK3.d.ts(200, 14): '"~standard"' is declared here.
The types of 'options.body' are incompatible between these types.
Property '"~standard"' is missing in type 'ZodObject<{ email: ZodString; type: ZodEnum<["email-verification", "sign-in", "forget-password"]>; }, "strip", ZodTypeAny, { email: string; type: "sign-in" | "email-verification" | "forget-password"; }, { email: string; type: "sign-in" | "email-verification" | "forget-password"; }>' but required in type 'StandardSchemaV1<unknown, unknown>'.ts(2322)
router-DQIhoWK3.d.ts(200, 14): '"~standard"' is declared here.
KiNFiSH
KiNFiSH2w ago
can you show me how you are actually calling it since it looks like validation issue also your auth config

Did you find this page helpful?