Better auth issue with prisma adapter using with Nuxt

I have an issue when building for production (works fine in dev) with some Es module saying dirname is not defined in ES module scope I have "type:module" in my package.json. can someone help me with this issue? I have my better-auth instance in lib/auth like this below import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { sendEmail, sendPasswordResetEmail } from "./email"; import prisma from "./prisma"; export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql", }), emailAndPassword: { enabled: true, sendResetPassword: async ({user, url, token}, request) => { try { await sendPasswordResetEmail(user.email, url); } catch (error) { throw new Error("Failed to send password reset email"); } }, }, }); and my prisma.ts in lib/prisma.ts import { PrismaClient } from '../generated/prisma' import { withAccelerate } from '@prisma/extension-accelerate' const globalForPrisma = global as unknown as { prisma: PrismaClient } const prisma = globalForPrisma.prisma || new PrismaClient().$extends(withAccelerate()) if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma export default prisma and my api route in server/api/[...all.ts] import { auth } from "~/lib/auth"; export default defineEventHandler((event) => { return auth.handler(toWebRequest(event)); }); and the error is `[request error] [unhandled] [POST] https://example.com/api/auth/sign-in/email ReferenceError: dirname is not defined in ES module scope at file:///var/task/chunks/routes/api/...all.mjs:873:16 ... 8 lines matching cause stack trace ... at async file:///var/task/chunks/build/server.mjs:1099:114 { cause: ReferenceError: __dirname is not defined in ES module scope
} `
1 Reply
wale96
wale96OP2w ago
Can someone help with this?

Did you find this page helpful?