[GH-ISSUE #3288] BetterAuth CLI generator unable to parse prisma schema #9555

Closed
opened 2026-04-13 05:04:02 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @cholasimmons on GitHub (Jul 7, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3288

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Run bunx @better-auth/cli generate on an Elysia project which has a PrismaORM schema file that includes the prismabox generator block

generator prismabox { 
  provider = "prismabox"
  typeboxImportDependencyName = "elysia"
  typeboxImportVariableName = "t"
  inputModel = true
  output   = "../generated/prismabox"
}

This will throw a really long error that includes throw this.SAVE_ERROR(new exceptions_public_1.MismatchedTokenException(msg, nextToken, previousToken));

Current vs. Expected behavior

The bunx @better-auth/cli generate script should generate the necessary files without error.
This only works when we comment out the prismabox generator code in ./prisma/schema.prisma

What version of Better Auth are you using?

1.2.12

Provide environment information

OS: Windows 11
Browser: Firefox 140.0.2
REST Client: Yaak 2025.4.0
All dependencies latest...
Elysia: 1.3.5
Prisma: 6.11.1

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"

const authBasePath = '/auth';
export const auth = betterAuth({
  basePath: authBasePath,
  database: prismaAdapter(db, {
        provider: "postgresql"
    }),
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

My repo should be able to replicate this error once you uncomment the prismabox generator.

Originally created by @cholasimmons on GitHub (Jul 7, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3288 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Run `bunx @better-auth/cli generate` on an Elysia project which has a PrismaORM schema file that includes the prismabox generator block ```prisma generator prismabox { provider = "prismabox" typeboxImportDependencyName = "elysia" typeboxImportVariableName = "t" inputModel = true output = "../generated/prismabox" } ``` This will throw a really long error that includes ` throw this.SAVE_ERROR(new exceptions_public_1.MismatchedTokenException(msg, nextToken, previousToken));` ### Current vs. Expected behavior The `bunx @better-auth/cli generate` script should generate the necessary files without error. This only works when we comment out the prismabox generator code in ./prisma/schema.prisma ### What version of Better Auth are you using? 1.2.12 ### Provide environment information ```bash OS: Windows 11 Browser: Firefox 140.0.2 REST Client: Yaak 2025.4.0 All dependencies latest... Elysia: 1.3.5 Prisma: 6.11.1 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" const authBasePath = '/auth'; export const auth = betterAuth({ basePath: authBasePath, database: prismaAdapter(db, { provider: "postgresql" }), emailAndPassword: { enabled: true }, }); ``` ### Additional context [My repo](https://github.com/cholasimmons/furr-buddies_api_elysia) should be able to replicate this error once you uncomment the prismabox generator.
Author
Owner

@dosubot[bot] commented on GitHub (Jul 7, 2025):

This is a known issue: the BetterAuth CLI generator uses its own Prisma schema parser (via @mrleebo/prisma-ast), which often fails when it encounters unknown or custom generator blocks like prismabox. This results in parsing errors such as MismatchedTokenException and prevents code generation unless you comment out the extra generator block[s][2959].

There isn't an official fix or documented support for multiple custom generator blocks in the current BetterAuth CLI version. The most reliable workaround is to temporarily comment out or remove the prismabox generator block, run the BetterAuth CLI to generate the schema, and then re-add your custom generator block afterward. This approach has been confirmed by other users facing the same issue[2959].

Recent changes in the CLI allow for more flexible custom adapters, but this doesn't address the core parsing limitation with extra generator blocks[3003]. For now, the workaround above is the best option until the parser is improved to tolerate unknown generator blocks.

References:

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

<!-- gh-comment-id:3044327583 --> @dosubot[bot] commented on GitHub (Jul 7, 2025): <!-- Answer --> This is a known issue: the BetterAuth CLI generator uses its own Prisma schema parser (via `@mrleebo/prisma-ast`), which often fails when it encounters unknown or custom generator blocks like `prismabox`. This results in parsing errors such as `MismatchedTokenException` and prevents code generation unless you comment out the extra generator block[s][2959]. There isn't an official fix or documented support for multiple custom generator blocks in the current BetterAuth CLI version. The most reliable workaround is to temporarily comment out or remove the `prismabox` generator block, run the BetterAuth CLI to generate the schema, and then re-add your custom generator block afterward. This approach has been confirmed by other users facing the same issue[2959]. Recent changes in the CLI allow for more flexible custom adapters, but this doesn't address the core parsing limitation with extra generator blocks[3003]. For now, the workaround above is the best option until the parser is improved to tolerate unknown generator blocks. References: - [Issue with parsing extra generator blocks](https://github.com/better-auth/better-auth/issues/2959) - [CLI adapter/generator logic discussion](https://github.com/better-auth/better-auth/issues/3003) <!-- 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/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fa253453-1cae-4603-9aeb-5a983099c564?feedback_type=other)</sup>&nbsp;&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/3288)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9555