Type Error: Type instantiation is excessively deep and possibly infinite

I recently upgraded to the latest version of better-auth and these errors started popping up randomly, before upgrading i wasn't getting such errors I'm using nextjs + hono, earlier i was using nextjs handler and i started getting these errors so i decided to try with the hono handler but it was of no use
./src/lib/auth-client.ts:4:27
▲ Type error: Type instantiation is excessively deep and possibly infinite.

▲ 2 | import { createAuthClient } from "better-auth/react";
▲ 3 |
▲ > 4 | export const authClient = createAuthClient({
▲ | ^
▲ 5 | baseURL: env.NEXT_PUBLIC_BASE_URL!,
▲ 6 | });
▲ 7 |
▲ Next.js build worker exited with code: 1 and signal: null
./src/lib/auth-client.ts:4:27
▲ Type error: Type instantiation is excessively deep and possibly infinite.

▲ 2 | import { createAuthClient } from "better-auth/react";
▲ 3 |
▲ > 4 | export const authClient = createAuthClient({
▲ | ^
▲ 5 | baseURL: env.NEXT_PUBLIC_BASE_URL!,
▲ 6 | });
▲ 7 |
▲ Next.js build worker exited with code: 1 and signal: null
similarly with the following code:
const session = await auth.api.getSession({
^^^^^^^^
headers: c.req.raw.headers,
});
Type instantiation is excessively deep and possibly infinite
const session = await auth.api.getSession({
^^^^^^^^
headers: c.req.raw.headers,
});
Type instantiation is excessively deep and possibly infinite
im using session in all the APIs but this error only pops up on any one of them, if i reload the vscode window, this error will appear on some other api -- "better-auth": "^1.1.21", "hono": "^4.7.2",
1 Reply
Dev
DevOP3d ago
auth.ts
export const auth = betterAuth({
database: drizzleAdapter(getDrizzleDb(), {
provider: "sqlite",
schema: {
user,
session,
account,
verification,
},
}),
user: {
deleteUser: {
enabled: true,
},
},
plugins: [openAPI()],
emailAndPassword: {
enabled: true,
},
secret: env.BETTER_AUTH_SECRET,
});
auth.ts
export const auth = betterAuth({
database: drizzleAdapter(getDrizzleDb(), {
provider: "sqlite",
schema: {
user,
session,
account,
verification,
},
}),
user: {
deleteUser: {
enabled: true,
},
},
plugins: [openAPI()],
emailAndPassword: {
enabled: true,
},
secret: env.BETTER_AUTH_SECRET,
});
src/app/api/[...route]/route.ts
import { Hono } from "hono";
import { handle } from "hono/vercel";
import { auth } from "@/lib/auth";

import hello from "./hello";
import user from "./user";
import chat from "./chat";
import messages from "./messages";

export const runtime = "edge";

const app = new Hono().basePath("/api");

const routes = app
.route("/hello", hello)
.route("/user", user)
.route("/chat", chat)
.route("/messages", messages);

app.on(["GET", "POST", "DELETE"], "/auth/*", (c) => {
return auth.handler(c.req.raw);
});

export const GET = handle(app);
export const POST = handle(app);
export const DELETE = handle(app);

export type AppType = typeof routes;
src/app/api/[...route]/route.ts
import { Hono } from "hono";
import { handle } from "hono/vercel";
import { auth } from "@/lib/auth";

import hello from "./hello";
import user from "./user";
import chat from "./chat";
import messages from "./messages";

export const runtime = "edge";

const app = new Hono().basePath("/api");

const routes = app
.route("/hello", hello)
.route("/user", user)
.route("/chat", chat)
.route("/messages", messages);

app.on(["GET", "POST", "DELETE"], "/auth/*", (c) => {
return auth.handler(c.req.raw);
});

export const GET = handle(app);
export const POST = handle(app);
export const DELETE = handle(app);

export type AppType = typeof routes;

Did you find this page helpful?