TanStackT
TanStack4mo ago
5 replies
faint-white

Error: createServerOnlyFn() functions can only be called on the server! (After RC)

I am getting this error after the new RC:
db.ts:10 Uncaught (in promise) Error: createServerOnlyFn() functions can only be called on the server!
at getDatabase (db.ts:10:18)
at db.ts:14:19
getDatabase @ db.ts:10
(anonymous) @ db.ts:14



import * as schema from "@/db/schema"
import { Pool } from "@neondatabase/serverless"
import { createServerOnlyFn } from "@tanstack/react-start"
import { drizzle } from "drizzle-orm/neon-serverless"

import { serverEnv } from "@/lib/env"

// Primary database connection
const driver = new Pool({ connectionString: serverEnv.DATABASE_URL })
const getDatabase = createServerOnlyFn(() =>
drizzle({ client: driver, schema, casing: "snake_case" })
)

export const db = getDatabase()
Was this page helpful?