[prisma-adapter] Must call super constructor in derived class before accessing 'this' or returning from derived constructor #2806

Closed
opened 2026-03-13 10:21:22 -05:00 by GiteaMirror · 6 comments
Owner

Originally created by @AdiMarianMutu on GitHub (Feb 1, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Just follow the official docs; Only difference (which may cause this error) is that I'm using NX v22.3.3.

Current vs. Expected behavior

When using an OAuth (tested only with Google), after selecting the user to use, the server fails because it can't create it.

Better auth gives exactly these 2 errors, without a stack trace:

2026-02-01T17:32:32.864Z ERROR [Better Auth]: ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constrctor

2026-02-01T17:32:32.865Z ERROR [Better Auth]: unable_to_create_user 

What version of Better Auth are you using?

1.4.18

System info

- NX v22.3.3
- better-auth v1.4.18 (`prisma` adapter)
- @better-auth/expo v1.4.18
- expo v54.0.32

Which area(s) are affected? (Select all that apply)

Backend, Package

Auth config (if applicable)

My better auth config:

import { expo } from '@better-auth/expo';
import { betterAuth } from 'better-auth';
import { prismaAdapter } from 'better-auth/adapters/prisma';

import { Constants } from '@org/lib/server';
import { SharedConstants } from '@org/lib/shared';

import { prismaClient } from '../db/prisma/client';
import { afterHooks, beforeHooks } from './hooks';

export const auth = betterAuth({
  database: prismaAdapter(prismaClient, {
    provider: 'postgresql',
    transaction: true,
  }),
  baseURL: Constants.Common.ServerUrl,
  basePath: `/${SharedConstants.Common.ServerApiPrefix}/auth`,
  plugins: [expo()],
  advanced: {
    database: {
      // The `id` columns should always be auto-incrementing numeric IDs which should be used only on the back-end.
      generateId: 'serial',
    },
  },
  experimental: {
    joins: true,
  },

  hooks: {
    before: beforeHooks,
    after: afterHooks,
  },

  //#region Core Tables (https://www.better-auth.com/docs/concepts/database#core-schema)

  user: {
    additionalFields: {
      uuid: {
        type: 'string',
        input: false,
        defaultValue: 'gen_random_uuid()',
        required: true,
      },
      firstName: {
        type: 'string',
        required: true,
      },
      middleName: {
        type: 'string',
        required: false,
      },
      lastName: {
        type: 'string',
        required: true,
      },
      country: {
        type: 'string',
        required: false,
      },
      isActive: {
        type: 'boolean',
        input: false,
        required: true,
        defaultValue: true,
      },
      isDeleted: {
        type: 'boolean',
        input: false,
        required: true,
        defaultValue: false,
      },
      toBeDeletedAt: {
        type: 'date',
        input: false,
        required: false,
      },
    },
  },

  //#endregion

  //#region Auth Strategies

  emailAndPassword: {
    enabled: false,
  },

  socialProviders: {
    // https://www.better-auth.com/docs/authentication/google
    google: {
      prompt: 'select_account',
      clientId: Constants.OAuth.Google.ClientId,
      clientSecret: Constants.OAuth.Google.ClientSecret,
      mapProfileToUser: (profile) => ({
        ...profile,
        firstName: profile.given_name,
        lastName: profile.family_name,
      }),
    },
    // https://www.better-auth.com/docs/authentication/apple
    apple: {
      prompt: 'select_account',
      clientId: process.env.APPLE_CLIENT_ID as string,
      clientSecret: process.env.APPLE_CLIENT_SECRET as string,
      // TODO: To be set once ready
      // appBundleIdentifier: process.env.APPLE_APP_BUNDLE_IDENTIFIER as string,
    },
    // https://www.better-auth.com/docs/authentication/linkedin
    linkedin: {
      prompt: 'select_account',
      clientId: process.env.LINKEDIN_CLIENT_ID as string,
      clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string,
    },
    // https://www.better-auth.com/docs/authentication/reddit
    reddit: {
      prompt: 'select_account',
      clientId: process.env.REDDIT_CLIENT_ID as string,
      clientSecret: process.env.REDDIT_CLIENT_SECRET as string,
    },
    // https://www.better-auth.com/docs/authentication/discord
    discord: {
      clientId: process.env.DISCORD_CLIENT_ID as string,
      clientSecret: process.env.DISCORD_CLIENT_SECRET as string,
    },
    // https://www.better-auth.com/docs/authentication/tiktok
    tiktok: {
      prompt: 'select_account',
      clientSecret: process.env.TIKTOK_CLIENT_SECRET as string,
      clientKey: process.env.TIKTOK_CLIENT_KEY as string,
    },
  },

  //#endregion

  trustedOrigins: [
    ...(SharedConstants.Build.IsDevEnv ? ['exp://', 'http://localhost:4200'] : []),
    `${SharedConstants.Common.AppName}://`,
    'https://appleid.apple.com',
  ],
});

export type UserSession = typeof auth.$Infer.Session;

And my prisma schema files:

//schema.prisma

generator client {
  provider = "prisma-client-js"
  output   = "../.client"
}

datasource db {
  provider = "postgresql"
}
//user.prisma

model User {
  id            Int            @id @default(autoincrement())
  uuid          String         @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
  name          String         @unique
  email         String         @unique
  emailVerified Boolean        @default(false) @map("email_verified")
  image         String?
  firstName     String         @map("first_name")
  middleName    String?        @map("middle_name")
  lastName      String         @map("last_name")
  country       String?
  isActive      Boolean        @default(true) @map("is_active")
  isDeleted     Boolean        @default(false) @map("is_deleted")
  toBeDeletedAt DateTime?      @map("to_be_deleted_at")
  createdAt     DateTime       @default(now()) @map("created_at")
  updatedAt     DateTime?      @updatedAt @map("updated_at")
  accounts      Account[]
  sessions      Session[]
  subscriptions Subscription[]

  @@map("users")
}
//auth.prisma

model Session {
  id        Int       @id @default(autoincrement())
  expiresAt DateTime  @map("expires_at")
  token     String    @unique
  ipAddress String?   @map("ip_address")
  userAgent String?   @map("user_agent")
  userId    Int       @map("user_id")
  createdAt DateTime  @default(now()) @map("created_at")
  updatedAt DateTime? @updatedAt @map("updated_at")
  user      User      @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId])
  @@map("sessions")
}

model Account {
  id                    Int       @id @default(autoincrement())
  accountId             String    @map("account_id")
  providerId            String    @map("provider_id")
  userId                Int       @map("user_id")
  accessToken           String?   @map("access_token")
  refreshToken          String?   @map("refresh_token")
  idToken               String?   @map("id_token")
  accessTokenExpiresAt  DateTime? @map("access_token_expires_at")
  refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at")
  scope                 String?
  password              String?
  createdAt             DateTime  @default(now()) @map("created_at")
  updatedAt             DateTime? @updatedAt @map("updated_at")
  user                  User      @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@index([userId])
  @@map("accounts")
}

model Verification {
  id         Int       @id @default(autoincrement())
  identifier String
  value      String
  expiresAt  DateTime  @map("expires_at")
  createdAt  DateTime  @default(now()) @map("created_at")
  updatedAt  DateTime? @updatedAt @map("updated_at")

  @@index([identifier])
  @@map("verifications")
}

Additional context

No response

Originally created by @AdiMarianMutu on GitHub (Feb 1, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Just follow the official docs; Only difference (which may cause this error) is that I'm using NX v22.3.3. ### Current vs. Expected behavior When using an OAuth (tested only with Google), after selecting the user to use, the server fails because it can't create it. Better auth gives exactly these 2 errors, without a stack trace: ```ps1 2026-02-01T17:32:32.864Z ERROR [Better Auth]: ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constrctor 2026-02-01T17:32:32.865Z ERROR [Better Auth]: unable_to_create_user ``` ### What version of Better Auth are you using? 1.4.18 ### System info ```bash - NX v22.3.3 - better-auth v1.4.18 (`prisma` adapter) - @better-auth/expo v1.4.18 - expo v54.0.32 ``` ### Which area(s) are affected? (Select all that apply) Backend, Package ### Auth config (if applicable) My better auth config: ```ts import { expo } from '@better-auth/expo'; import { betterAuth } from 'better-auth'; import { prismaAdapter } from 'better-auth/adapters/prisma'; import { Constants } from '@org/lib/server'; import { SharedConstants } from '@org/lib/shared'; import { prismaClient } from '../db/prisma/client'; import { afterHooks, beforeHooks } from './hooks'; export const auth = betterAuth({ database: prismaAdapter(prismaClient, { provider: 'postgresql', transaction: true, }), baseURL: Constants.Common.ServerUrl, basePath: `/${SharedConstants.Common.ServerApiPrefix}/auth`, plugins: [expo()], advanced: { database: { // The `id` columns should always be auto-incrementing numeric IDs which should be used only on the back-end. generateId: 'serial', }, }, experimental: { joins: true, }, hooks: { before: beforeHooks, after: afterHooks, }, //#region Core Tables (https://www.better-auth.com/docs/concepts/database#core-schema) user: { additionalFields: { uuid: { type: 'string', input: false, defaultValue: 'gen_random_uuid()', required: true, }, firstName: { type: 'string', required: true, }, middleName: { type: 'string', required: false, }, lastName: { type: 'string', required: true, }, country: { type: 'string', required: false, }, isActive: { type: 'boolean', input: false, required: true, defaultValue: true, }, isDeleted: { type: 'boolean', input: false, required: true, defaultValue: false, }, toBeDeletedAt: { type: 'date', input: false, required: false, }, }, }, //#endregion //#region Auth Strategies emailAndPassword: { enabled: false, }, socialProviders: { // https://www.better-auth.com/docs/authentication/google google: { prompt: 'select_account', clientId: Constants.OAuth.Google.ClientId, clientSecret: Constants.OAuth.Google.ClientSecret, mapProfileToUser: (profile) => ({ ...profile, firstName: profile.given_name, lastName: profile.family_name, }), }, // https://www.better-auth.com/docs/authentication/apple apple: { prompt: 'select_account', clientId: process.env.APPLE_CLIENT_ID as string, clientSecret: process.env.APPLE_CLIENT_SECRET as string, // TODO: To be set once ready // appBundleIdentifier: process.env.APPLE_APP_BUNDLE_IDENTIFIER as string, }, // https://www.better-auth.com/docs/authentication/linkedin linkedin: { prompt: 'select_account', clientId: process.env.LINKEDIN_CLIENT_ID as string, clientSecret: process.env.LINKEDIN_CLIENT_SECRET as string, }, // https://www.better-auth.com/docs/authentication/reddit reddit: { prompt: 'select_account', clientId: process.env.REDDIT_CLIENT_ID as string, clientSecret: process.env.REDDIT_CLIENT_SECRET as string, }, // https://www.better-auth.com/docs/authentication/discord discord: { clientId: process.env.DISCORD_CLIENT_ID as string, clientSecret: process.env.DISCORD_CLIENT_SECRET as string, }, // https://www.better-auth.com/docs/authentication/tiktok tiktok: { prompt: 'select_account', clientSecret: process.env.TIKTOK_CLIENT_SECRET as string, clientKey: process.env.TIKTOK_CLIENT_KEY as string, }, }, //#endregion trustedOrigins: [ ...(SharedConstants.Build.IsDevEnv ? ['exp://', 'http://localhost:4200'] : []), `${SharedConstants.Common.AppName}://`, 'https://appleid.apple.com', ], }); export type UserSession = typeof auth.$Infer.Session; ``` And my prisma schema files: ```schema.prisma //schema.prisma generator client { provider = "prisma-client-js" output = "../.client" } datasource db { provider = "postgresql" } ``` ```user.prisma //user.prisma model User { id Int @id @default(autoincrement()) uuid String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid name String @unique email String @unique emailVerified Boolean @default(false) @map("email_verified") image String? firstName String @map("first_name") middleName String? @map("middle_name") lastName String @map("last_name") country String? isActive Boolean @default(true) @map("is_active") isDeleted Boolean @default(false) @map("is_deleted") toBeDeletedAt DateTime? @map("to_be_deleted_at") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime? @updatedAt @map("updated_at") accounts Account[] sessions Session[] subscriptions Subscription[] @@map("users") } ``` ```auth.prisma //auth.prisma model Session { id Int @id @default(autoincrement()) expiresAt DateTime @map("expires_at") token String @unique ipAddress String? @map("ip_address") userAgent String? @map("user_agent") userId Int @map("user_id") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime? @updatedAt @map("updated_at") user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@index([userId]) @@map("sessions") } model Account { id Int @id @default(autoincrement()) accountId String @map("account_id") providerId String @map("provider_id") userId Int @map("user_id") accessToken String? @map("access_token") refreshToken String? @map("refresh_token") idToken String? @map("id_token") accessTokenExpiresAt DateTime? @map("access_token_expires_at") refreshTokenExpiresAt DateTime? @map("refresh_token_expires_at") scope String? password String? createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime? @updatedAt @map("updated_at") user User @relation(fields: [userId], references: [id], onDelete: Cascade) @@index([userId]) @@map("accounts") } model Verification { id Int @id @default(autoincrement()) identifier String value String expiresAt DateTime @map("expires_at") createdAt DateTime @default(now()) @map("created_at") updatedAt DateTime? @updatedAt @map("updated_at") @@index([identifier]) @@map("verifications") } ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 10:21:22 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Feb 1, 2026):

The error you're encountering, "Must call super constructor in derived class before accessing 'this' or returning from derived constructor," typically indicates a problem in the class hierarchy of your code. In the context of Better Auth and the Prisma adapter, it suggests that there might be an issue with how your custom adapter (in this case, the Prisma adapter) is being set up or used.

Here are some troubleshooting steps you can follow:

  1. Verify Class Inheritance: Check if you are correctly calling the superclass constructor in your custom classes that extend from a base class. This is essential in JavaScript/TypeScript class hierarchies.

  2. Look for Updates: Check if there are updates or patches for Better Auth or the Prisma adapter that address this issue.

  3. Configuration Review: Double-check your authentication and adapter configuration, particularly ensuring that the prismaAdapter is instantiated appropriately with the necessary parameters.

  4. Error Logging: Enhance error logging to capture more details if this issue arises again. This will help in identifying the real source of the problem.

If these steps do not resolve the issue, please consider tagging a member of the Better Auth team—@bekacru or @ping__—for further assistance.

What specific part of your integration do you think might be causing this issue?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Feb 1, 2026): The error you're encountering, "Must call super constructor in derived class before accessing 'this' or returning from derived constructor," typically indicates a problem in the class hierarchy of your code. In the context of Better Auth and the Prisma adapter, it suggests that there might be an issue with how your custom adapter (in this case, the Prisma adapter) is being set up or used. Here are some troubleshooting steps you can follow: 1. **Verify Class Inheritance**: Check if you are correctly calling the superclass constructor in your custom classes that extend from a base class. This is essential in JavaScript/TypeScript class hierarchies. 2. **Look for Updates**: Check if there are updates or patches for Better Auth or the Prisma adapter that address this issue. 3. **Configuration Review**: Double-check your authentication and adapter configuration, particularly ensuring that the `prismaAdapter` is instantiated appropriately with the necessary parameters. 4. **Error Logging**: Enhance error logging to capture more details if this issue arises again. This will help in identifying the real source of the problem. If these steps do not resolve the issue, please consider tagging a member of the Better Auth team—@bekacru or @ping__—for further assistance. What specific part of your integration do you think might be causing this issue? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Feb 1, 2026):

This error isn’t coming from the Better Auth prisma adapter, core OAuth flow, or the expo plugin—they all use plain functions and async handlers, not class inheritance, so there’s no missing super() call in those paths. The error is likely triggered by a custom hook (beforeHooks, afterHooks) or a plugin in your project that uses class inheritance incorrectly, or by a build artifact from NX that transforms async code in a way that breaks generator inheritance.

To isolate the cause, try these steps:

  1. Temporarily remove your custom hooks (beforeHooks, afterHooks) and the expo plugin from your Better Auth config. If the error disappears, the issue is in one of those hooks or plugins.
  2. Enable debug logs in the prisma adapter by passing debugLogs: true in its config—this may surface a more detailed stack trace.
  3. If the error persists, try running your setup outside of NX with a minimal config and default schema to see if NX’s build process is introducing the problem.
  4. If you identify a specific hook or plugin as the trigger, review its implementation for any class that extends another class but forgets to call super() in the constructor, or for async generator functions that might be transpiled incorrectly.

If you want more targeted help, share the code for your beforeHooks and afterHooks. This will help pinpoint if the error is coming from there.

References:

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 1, 2026): <!-- Answer --> This error isn’t coming from the Better Auth prisma adapter, core OAuth flow, or the expo plugin—they all use plain functions and async handlers, not class inheritance, so there’s no missing super() call in those paths. The error is likely triggered by a custom hook (beforeHooks, afterHooks) or a plugin in your project that uses class inheritance incorrectly, or by a build artifact from NX that transforms async code in a way that breaks generator inheritance. To isolate the cause, try these steps: 1. Temporarily remove your custom hooks (beforeHooks, afterHooks) and the expo plugin from your Better Auth config. If the error disappears, the issue is in one of those hooks or plugins. 2. Enable debug logs in the prisma adapter by passing debugLogs: true in its config—this may surface a more detailed stack trace. 3. If the error persists, try running your setup outside of NX with a minimal config and default schema to see if NX’s build process is introducing the problem. 4. If you identify a specific hook or plugin as the trigger, review its implementation for any class that extends another class but forgets to call super() in the constructor, or for async generator functions that might be transpiled incorrectly. If you want more targeted help, share the code for your beforeHooks and afterHooks. This will help pinpoint if the error is coming from there. References: - [Custom hooks and plugins in Better Auth are implemented as plain functions, not classes](https://github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/core/src/types/init-options.ts#L642-L1467) - [Expo plugin implementation (no class inheritance)](https://github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/expo/src/index.ts#L1-L90) - [Similar ReferenceError reported in a plugin context](https://github.com/better-auth/better-auth/issues/5483) - [Debug logs option in prisma adapter](https://github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts#L13-L558) <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/466c2311-4795-4443-81ef-e8288942552b?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20error%20isn%E2%80%99t%20coming%20from%20the%20Better%20Auth%20prisma%20adapter%2C%20core%20OAuth%20flow%2C%20or%20the%20expo%20plugin%E2%80%94they%20all%20use%20plain%20functions%20and%20async%20handlers%2C%20not%20class%20inheritance%2C%20so%20there%E2%80%99s%20no%20missing%20super%28%29%20call%20in%20those%20paths.%20The%20error%20is%20likely%20triggered%20by%20a%20custom%20hook%20%28beforeHooks%2C%20afterHooks%29%20or%20a%20plugin%20in%20your%20project%20that%20uses%20class%20inheritance%20incorrectly%2C%20or%20by%20a%20build%20artifact%20from%20NX%20that%20transforms%20async%20code%20in%20a%20way%20that%20breaks%20generator%20inheritance.%0A%0ATo%20isolate%20the%20cause%2C%20try%20these%20steps%3A%0A%0A1.%20Temporarily%20remove%20your%20custom%20hooks%20%28beforeHooks%2C%20afterHooks%29%20and%20the%20expo%20plugin%20from%20your%20Better%20Auth%20config.%20If%20the%20error%20disappears%2C%20the%20issue%20is%20in%20one%20of%20those%20hooks%20or%20plugins.%0A2.%20Enable%20debug%20logs%20in%20the%20prisma%20adapter%20by%20passing%20debugLogs%3A%20true%20in%20its%20config%E2%80%94this%20may%20surface%20a%20more%20detailed%20stack%20trace.%0A3.%20If%20the%20error%20persists%2C%20try%20running%20your%20setup%20outside%20of%20NX%20with%20a%20minimal%20config%20and%20default%20schema%20to%20see%20if%20NX%E2%80%99s%20build%20process%20is%20introducing%20the%20problem.%0A4.%20If%20you%20identify%20a%20specific%20hook%20or%20plugin%20as%20the%20trigger%2C%20review%20its%20implementation%20for%20any%20class%20that%20extends%20another%20class%20but%20forgets%20to%20call%20super%28%29%20in%20the%20constructor%2C%20or%20for%20async%20generator%20functions%20that%20might%20be%20transpiled%20incorrectly.%0A%0AIf%20you%20want%20more%20targeted%20help%2C%20share%20the%20code%20for%20your%20beforeHooks%20and%20afterHooks.%20This%20will%20help%20pinpoint%20if%20the%20error%20is%20coming%20from%20there.%0A%0AReferences%3A%0A-%20%5BCustom%20hooks%20and%20plugins%20in%20Better%20Auth%20are%20implemented%20as%20plain%20functions%2C%20not%20classes%5D%28https%3A//github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/core/src/types/init-options.ts%23L642-L1467%29%0A-%20%5BExpo%20plugin%20implementation%20%28no%20class%20inheritance%29%5D%28https%3A//github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/expo/src/index.ts%23L1-L90%29%0A-%20%5BSimilar%20ReferenceError%20reported%20in%20a%20plugin%20context%5D%28https%3A//github.com/better-auth/better-auth/issues/5483%29%0A-%20%5BDebug%20logs%20option%20in%20prisma%20adapter%5D%28https%3A//github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts%23L13-L558%29)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7754)
Author
Owner

@AdiMarianMutu commented on GitHub (Feb 1, 2026):

@dosubot

  1. I confirm that it's not from the hooks as I temporarily removed them
  2. Debug logs of the prisma adapter right before failing are:
2026-02-01T18:17:14.005Z INFO [Better Auth]: [Prisma Adapter] #8 [2/4] create (Parsed Input): {
  model: 'user',
  data: {
    name: 'Adi-Marian Mutu',
    email: '***',
    emailVerified: true,
    image: '***',
    createdAt: 2026-02-01T18:17:14.005Z,
    updatedAt: 2026-02-01T18:17:14.005Z,
    uuid: 'gen_random_uuid()',
    firstName: 'Adi-Marian',
    lastName: 'Mutu',
    isActive: true,
    isDeleted: false
  }
}
  1. It's very difficult to do that as NX monorepo architecture is deeply rooted within the project...
@AdiMarianMutu commented on GitHub (Feb 1, 2026): @dosubot 1. I confirm that it's not from the hooks as I temporarily removed them 2. Debug logs of the `prisma` adapter right before failing are: ```sh 2026-02-01T18:17:14.005Z INFO [Better Auth]: [Prisma Adapter] #8 [2/4] create (Parsed Input): { model: 'user', data: { name: 'Adi-Marian Mutu', email: '***', emailVerified: true, image: '***', createdAt: 2026-02-01T18:17:14.005Z, updatedAt: 2026-02-01T18:17:14.005Z, uuid: 'gen_random_uuid()', firstName: 'Adi-Marian', lastName: 'Mutu', isActive: true, isDeleted: false } } ``` 3. It's very difficult to do that as `NX` monorepo architecture is deeply rooted within the project...
Author
Owner

@dosubot[bot] commented on GitHub (Feb 1, 2026):

This error is almost certainly caused by how NX is transpiling or bundling dependencies that use ES6+ class syntax, not by your Better Auth config or the prisma adapter itself (which uses only plain functions—no classes or super calls) source.

Here's what you should do:

  1. In your package.json, add an override to pin better-call to version 1.0.15 (or later), then reinstall dependencies. Example:

    "overrides": {
      "better-call": "1.0.15"
    }
    

    This fixes a known issue where older better-call versions shipped ES6+ class syntax that breaks in some build environments source.

  2. Update your NX (or underlying build tool) config to exclude better-auth and better-call from dependency optimization/transpilation. In Vite, this is done with optimizeDeps.exclude: ['better-auth', 'better-call']; for NX, look for a similar setting in your build pipeline source.

  3. In your Better Auth config, remove the uuid field from the user creation data (or ensure it's omitted when creating users). Let the database generate the UUID using its default, rather than passing the string 'gen_random_uuid()' source.

  4. If the error persists, try to capture a full stack trace (with source maps enabled) to pinpoint the exact file and dependency where the ReferenceError is thrown.

Let me know if you need help with any of these steps or if you get a new error after making these changes.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 1, 2026): <!-- Answer --> This error is almost certainly caused by how NX is transpiling or bundling dependencies that use ES6+ class syntax, not by your Better Auth config or the prisma adapter itself (which uses only plain functions—no classes or super calls) [source](https://github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts#L13-L558). Here's what you should do: 1. In your package.json, add an override to pin better-call to version 1.0.15 (or later), then reinstall dependencies. Example: ```json "overrides": { "better-call": "1.0.15" } ``` This fixes a known issue where older better-call versions shipped ES6+ class syntax that breaks in some build environments [source](https://github.com/better-auth/better-auth/issues/4082#issuecomment-3201483232). 2. Update your NX (or underlying build tool) config to exclude better-auth and better-call from dependency optimization/transpilation. In Vite, this is done with `optimizeDeps.exclude: ['better-auth', 'better-call']`; for NX, look for a similar setting in your build pipeline [source](https://github.com/better-auth/better-auth/issues/4541#issuecomment-3271030028). 3. In your Better Auth config, remove the uuid field from the user creation data (or ensure it's omitted when creating users). Let the database generate the UUID using its default, rather than passing the string 'gen_random_uuid()' [source](https://github.com/better-auth/better-auth/pull/7474). 4. If the error persists, try to capture a full stack trace (with source maps enabled) to pinpoint the exact file and dependency where the ReferenceError is thrown. Let me know if you need help with any of these steps or if you get a new error after making these changes. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/450d77d7-1a55-4724-98e6-0592a4ed7dbd?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20error%20is%20almost%20certainly%20caused%20by%20how%20NX%20is%20transpiling%20or%20bundling%20dependencies%20that%20use%20ES6%2B%20class%20syntax%2C%20not%20by%20your%20Better%20Auth%20config%20or%20the%20prisma%20adapter%20itself%20%28which%20uses%20only%20plain%20functions%E2%80%94no%20classes%20or%20super%20calls%29%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/583f12fb7db38681ee882d219ce3895faa4a6976/packages/better-auth/src/adapters/prisma-adapter/prisma-adapter.ts%23L13-L558%29.%0A%0AHere%27s%20what%20you%20should%20do%3A%0A%0A1.%20In%20your%20package.json%2C%20add%20an%20override%20to%20pin%20better-call%20to%20version%201.0.15%20%28or%20later%29%2C%20then%20reinstall%20dependencies.%20Example%3A%0A%20%20%20%60%60%60json%0A%20%20%20%22overrides%22%3A%20%7B%0A%20%20%20%20%20%22better-call%22%3A%20%221.0.15%22%0A%20%20%20%7D%0A%20%20%20%60%60%60%0A%20%20%20This%20fixes%20a%20known%20issue%20where%20older%20better-call%20versions%20shipped%20ES6%2B%20class%20syntax%20that%20breaks%20in%20some%20build%20environments%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4082%23issuecomment-3201483232%29.%0A%0A2.%20Update%20your%20NX%20%28or%20underlying%20build%20tool%29%20config%20to%20exclude%20better-auth%20and%20better-call%20from%20dependency%20optimization/transpilation.%20In%20Vite%2C%20this%20is%20done%20with%20%60optimizeDeps.exclude%3A%20%5B%27better-auth%27%2C%20%27better-call%27%5D%60%3B%20for%20NX%2C%20look%20for%20a%20similar%20setting%20in%20your%20build%20pipeline%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4541%23issuecomment-3271030028%29.%0A%0A3.%20In%20your%20Better%20Auth%20config%2C%20remove%20the%20uuid%20field%20from%20the%20user%20creation%20data%20%28or%20ensure%20it%27s%20omitted%20when%20creating%20users%29.%20Let%20the%20database%20generate%20the%20UUID%20using%20its%20default%2C%20rather%20than%20passing%20the%20string%20%27gen_random_uuid%28%29%27%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/pull/7474%29.%0A%0A4.%20If%20the%20error%20persists%2C%20try%20to%20capture%20a%20full%20stack%20trace%20%28with%20source%20maps%20enabled%29%20to%20pinpoint%20the%20exact%20file%20and%20dependency%20where%20the%20ReferenceError%20is%20thrown.%0A%0ALet%20me%20know%20if%20you%20need%20help%20with%20any%20of%20these%20steps%20or%20if%20you%20get%20a%20new%20error%20after%20making%20these%20changes.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7754)
Author
Owner

@AdiMarianMutu commented on GitHub (Feb 1, 2026):

@dosubot

Point no. 3 was the root cause. Removing the defaultValue fixed the issue, thanks!

user: {
  additionalField: {
    uuid: {
     type: 'string',
     input: false,
     // defaultValue: 'gen_random_uuid()',
     required: false,
    }
  }
}
@AdiMarianMutu commented on GitHub (Feb 1, 2026): @dosubot Point no. 3 was the root cause. Removing the `defaultValue` fixed the issue, thanks! ```ts user: { additionalField: { uuid: { type: 'string', input: false, // defaultValue: 'gen_random_uuid()', required: false, } } } ```
Author
Owner

@dosubot[bot] commented on GitHub (Feb 1, 2026):

You're welcome! Omitting the defaultValue for uuid is the right approach here—this way, Prisma lets your database generate the UUID using its default, instead of passing the string 'gen_random_uuid()' as a value, which avoids the error. If you run into any more issues or have questions about custom fields or adapters, just let me know!

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 1, 2026): <!-- Answer --> You're welcome! Omitting the defaultValue for uuid is the right approach here—this way, Prisma lets your database generate the UUID using its default, instead of passing the string 'gen_random_uuid()' as a value, which avoids the error. If you run into any more issues or have questions about custom fields or adapters, just let me know! <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/344c67d4-6dab-4247-aed0-4dce9246940e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=You%27re%20welcome%21%20Omitting%20the%20defaultValue%20for%20uuid%20is%20the%20right%20approach%20here%E2%80%94this%20way%2C%20Prisma%20lets%20your%20database%20generate%20the%20UUID%20using%20its%20default%2C%20instead%20of%20passing%20the%20string%20%27gen_random_uuid%28%29%27%20as%20a%20value%2C%20which%20avoids%20the%20error.%20If%20you%20run%20into%20any%20more%20issues%20or%20have%20questions%20about%20custom%20fields%20or%20adapters%2C%20just%20let%20me%20know%21)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7754)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2806