[GH-ISSUE #7033] BetterAuth CLI cannot read Prisma client in NestJS project (MODULE_NOT_FOUND) #10707

Open
opened 2026-04-13 07:00:21 -05:00 by GiteaMirror · 14 comments
Owner

Originally created by @Rayan-Allali on GitHub (Dec 27, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7033

Originally assigned to: @bytaesu on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a NestJS project.
  2. Install Prisma and generate client:
pnpm add @prisma/client
pnpm prisma generate
  1. Create a BetterAuth config file:
// src/features/auth/better-auth.ts
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "../../generated/prisma/client"; // current import
import { VALIDATED_ENV } from "../../config/env.config";

const prisma = new PrismaClient();

export const auth = betterAuth({
  database: prismaAdapter(prisma, { provider: "postgresql" }),
});
  1. Run the CLI:
npx @better-auth/cli generate --config src/features/auth/better-auth.ts

Current vs. Expected behavior

Actual Behavior

  • CLI throws MODULE_NOT_FOUND for @prisma/client/runtime/library.
  • Happens even though Prisma works normally in NestJS.

Expected Behavior

  • CLI should import the Prisma client and generate the necessary BetterAuth files.

What version of Better Auth are you using?

1.4.9

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home",
    "release": "10.0.26200",
    "cpuCount": 12,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-1265U",
    "totalMemory": "7.83 GB",
    "freeMemory": "0.55 GB"
  },
  "node": {
    "version": "v22.21.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.4"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "@prisma/client",
      "version": "^7.2.0"
    }
  ],
  "betterAuth": {
    "version": "^1.4.9",
    "config": null
  }

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

Other

Auth config (if applicable)

// src/features/auth/better-auth.ts
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "../../generated/prisma/client"; // current import
import { VALIDATED_ENV } from "../../config/env.config";

const prisma = new PrismaClient();

export const auth = betterAuth({
  database: prismaAdapter(prisma, { provider: "postgresql" }),
});

Additional context

No response

Originally created by @Rayan-Allali on GitHub (Dec 27, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7033 Originally assigned to: @bytaesu on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a NestJS project. 2. Install Prisma and generate client: ```bash pnpm add @prisma/client pnpm prisma generate ``` 3. Create a BetterAuth config file: ```ts // src/features/auth/better-auth.ts import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { PrismaClient } from "../../generated/prisma/client"; // current import import { VALIDATED_ENV } from "../../config/env.config"; const prisma = new PrismaClient(); export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql" }), }); ``` 4. Run the CLI: ```bash npx @better-auth/cli generate --config src/features/auth/better-auth.ts ``` ### Current vs. Expected behavior ### **Actual Behavior** * CLI throws `MODULE_NOT_FOUND` for `@prisma/client/runtime/library`. * Happens even though Prisma works normally in NestJS. ### **Expected Behavior** * CLI should import the Prisma client and generate the necessary BetterAuth files. ### What version of Better Auth are you using? 1.4.9 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home", "release": "10.0.26200", "cpuCount": 12, "cpuModel": "12th Gen Intel(R) Core(TM) i7-1265U", "totalMemory": "7.83 GB", "freeMemory": "0.55 GB" }, "node": { "version": "v22.21.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.4" }, "frameworks": null, "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "@prisma/client", "version": "^7.2.0" } ], "betterAuth": { "version": "^1.4.9", "config": null } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript // src/features/auth/better-auth.ts import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { PrismaClient } from "../../generated/prisma/client"; // current import import { VALIDATED_ENV } from "../../config/env.config"; const prisma = new PrismaClient(); export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql" }), }); ``` ### Additional context _No response_
GiteaMirror added the devtoolsbug labels 2026-04-13 07:00:21 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 27, 2025):

It looks like you're encountering a MODULE_NOT_FOUND error when trying to use the BetterAuth CLI in a NestJS project with Prisma. This issue can sometimes arise due to version conflicts or incorrect configuration.

Here are some steps you can take to troubleshoot:

  1. Check Prisma Client Installation: Ensure that @prisma/client is properly installed in your project. You might want to check your package.json and run pnpm install or npm install to ensure all packages are correctly set up.

  2. Verify BetterAuth Configuration: Make sure your better-auth.ts config file is set up correctly, ensuring the PrismaClient is properly imported from the correct path. The import should match the structure of your generated Prisma client.

  3. Update Dependencies: Sometimes, updating BetterAuth to the latest version might resolve compatibility issues with Prisma. You are currently using version 1.4.9; you could check if there is a newer version available.

  4. Clear Node Modules and Cache: If the issue persists, you can try deleting your node_modules folder and your lock file (pnpm-lock.yaml or package-lock.json), and then reinstalling your packages. This often clears up any lingering conflicts.

  5. Dynamic Import: Consider using dynamic import for your Prisma client in the better-auth.ts configuration to ensure proper loading.

If these steps don't resolve the issue, it might be useful to tag @bekacru or @ping__ in your GitHub thread for more specialized assistance, as they are part of the BetterAuth team and can provide direct support.

Have you tried any of these troubleshooting steps? If so, what were the results?

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3694305787 --> @better-auth-agent[bot] commented on GitHub (Dec 27, 2025): It looks like you're encountering a `MODULE_NOT_FOUND` error when trying to use the BetterAuth CLI in a NestJS project with Prisma. This issue can sometimes arise due to version conflicts or incorrect configuration. Here are some steps you can take to troubleshoot: 1. **Check Prisma Client Installation**: Ensure that `@prisma/client` is properly installed in your project. You might want to check your `package.json` and run `pnpm install` or `npm install` to ensure all packages are correctly set up. 2. **Verify BetterAuth Configuration**: Make sure your `better-auth.ts` config file is set up correctly, ensuring the `PrismaClient` is properly imported from the correct path. The import should match the structure of your generated Prisma client. 3. **Update Dependencies**: Sometimes, updating BetterAuth to the latest version might resolve compatibility issues with Prisma. You are currently using version 1.4.9; you could check if there is a newer version available. 4. **Clear Node Modules and Cache**: If the issue persists, you can try deleting your `node_modules` folder and your lock file (`pnpm-lock.yaml` or `package-lock.json`), and then reinstalling your packages. This often clears up any lingering conflicts. 5. **Dynamic Import**: Consider using dynamic import for your Prisma client in the `better-auth.ts` configuration to ensure proper loading. If these steps don't resolve the issue, it might be useful to tag @bekacru or @ping__ in your GitHub thread for more specialized assistance, as they are part of the BetterAuth team and can provide direct support. Have you tried any of these troubleshooting steps? If so, what were the results? _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/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 27, 2025):

Hi @Rayan-Allali! I'm Dosu and I’m helping the better-auth team.

This error happens because the BetterAuth CLI expects the Prisma client to be imported from its default location (@prisma/client). When you use a custom output path for the Prisma client (like ../../generated/prisma/client), the CLI often can't resolve it, especially when running outside your app's runtime context. This is a known issue with custom Prisma client output paths and BetterAuth CLI, especially with Prisma v7+ and in monorepo or non-standard project structures [source][source][source].

How to fix:

  • If possible, remove the output field from your generator client block in schema.prisma, run pnpm prisma generate, and update your import to:

    import { PrismaClient } from "@prisma/client";
    

    Then re-run the BetterAuth CLI. This resolves the MODULE_NOT_FOUND error in almost all cases [source][source].

  • If you must use a custom output path, make sure the import path in your config exactly matches the generated location, and use a relative path (not a path alias like @/generated/prisma/client). For example:

    import { PrismaClient } from "../../generated/prisma/client";
    

    But be aware that this can still fail if the CLI's working directory or module resolution context can't find the file. In that case, reverting to the default output is the most reliable fix [source].

  • Avoid using TypeScript path aliases in your BetterAuth config, as the CLI uses jiti for module loading, which does not resolve aliases unless your tsconfig.json is perfectly configured and accessible from the CLI's working directory [source].

  • Make sure your auth instance is exported as a named export (export const auth = ...), not a default export, so the CLI can find it [source].

  • If you still see the error after these changes, try clearing your npm cache and reinstalling dependencies.

There are also some known compatibility issues between BetterAuth CLI and Prisma v7, especially around custom output paths and schema changes. Until full support lands, using the default Prisma client location is the safest approach [source].

Let me know if you need help with a specific schema.prisma config or project structure!

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

<!-- gh-comment-id:3694307586 --> @dosubot[bot] commented on GitHub (Dec 27, 2025): <!-- Greeting --> Hi @Rayan-Allali! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This error happens because the BetterAuth CLI expects the Prisma client to be imported from its default location (`@prisma/client`). When you use a custom output path for the Prisma client (like `../../generated/prisma/client`), the CLI often can't resolve it, especially when running outside your app's runtime context. This is a known issue with custom Prisma client output paths and BetterAuth CLI, especially with Prisma v7+ and in monorepo or non-standard project structures [[source](https://github.com/better-auth/better-auth/issues/2207)][[source](https://github.com/better-auth/better-auth/issues/4670)][[source](https://github.com/better-auth/better-auth/issues/3736)]. **How to fix:** - If possible, remove the `output` field from your `generator client` block in `schema.prisma`, run `pnpm prisma generate`, and update your import to: ```ts import { PrismaClient } from "@prisma/client"; ``` Then re-run the BetterAuth CLI. This resolves the MODULE_NOT_FOUND error in almost all cases [[source](https://github.com/better-auth/better-auth/issues/4670)][[source](https://github.com/better-auth/better-auth/issues/3736)]. - If you must use a custom output path, make sure the import path in your config exactly matches the generated location, and use a relative path (not a path alias like `@/generated/prisma/client`). For example: ```ts import { PrismaClient } from "../../generated/prisma/client"; ``` But be aware that this can still fail if the CLI's working directory or module resolution context can't find the file. In that case, reverting to the default output is the most reliable fix [[source](https://github.com/better-auth/better-auth/issues/2207)]. - Avoid using TypeScript path aliases in your BetterAuth config, as the CLI uses `jiti` for module loading, which does not resolve aliases unless your `tsconfig.json` is perfectly configured and accessible from the CLI's working directory [[source](https://github.com/better-auth/better-auth/issues/6373)]. - Make sure your `auth` instance is exported as a named export (`export const auth = ...`), not a default export, so the CLI can find it [[source](https://github.com/better-auth/better-auth/issues/4670)]. - If you still see the error after these changes, try clearing your npm cache and reinstalling dependencies. There are also some known compatibility issues between BetterAuth CLI and Prisma v7, especially around custom output paths and schema changes. Until full support lands, using the default Prisma client location is the safest approach [[source](https://github.com/better-auth/better-auth/issues/6469)]. Let me know if you need help with a specific `schema.prisma` config or project structure! <!-- 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/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fca3a59b-8cd9-4361-bd3c-ba08799f85ce?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%20happens%20because%20the%20BetterAuth%20CLI%20expects%20the%20Prisma%20client%20to%20be%20imported%20from%20its%20default%20location%20%28%60%40prisma/client%60%29.%20When%20you%20use%20a%20custom%20output%20path%20for%20the%20Prisma%20client%20%28like%20%60../../generated/prisma/client%60%29%2C%20the%20CLI%20often%20can%27t%20resolve%20it%2C%20especially%20when%20running%20outside%20your%20app%27s%20runtime%20context.%20This%20is%20a%20known%20issue%20with%20custom%20Prisma%20client%20output%20paths%20and%20BetterAuth%20CLI%2C%20especially%20with%20Prisma%20v7%2B%20and%20in%20monorepo%20or%20non-standard%20project%20structures%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/2207%29%5D%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4670%29%5D%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/3736%29%5D.%0A%0A%2A%2AHow%20to%20fix%3A%2A%2A%0A%0A-%20If%20possible%2C%20remove%20the%20%60output%60%20field%20from%20your%20%60generator%20client%60%20block%20in%20%60schema.prisma%60%2C%20run%20%60pnpm%20prisma%20generate%60%2C%20and%20update%20your%20import%20to%3A%0A%20%20%60%60%60ts%0A%20%20import%20%7B%20PrismaClient%20%7D%20from%20%22%40prisma/client%22%3B%0A%20%20%60%60%60%0A%20%20Then%20re-run%20the%20BetterAuth%20CLI.%20This%20resolves%20the%20MODULE_NOT_FOUND%20error%20in%20almost%20all%20cases%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4670%29%5D%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/3736%29%5D.%0A%0A-%20If%20you%20must%20use%20a%20custom%20output%20path%2C%20make%20sure%20the%20import%20path%20in%20your%20config%20exactly%20matches%20the%20generated%20location%2C%20and%20use%20a%20relative%20path%20%28not%20a%20path%20alias%20like%20%60%40/generated/prisma/client%60%29.%20For%20example%3A%0A%20%20%60%60%60ts%0A%20%20import%20%7B%20PrismaClient%20%7D%20from%20%22../../generated/prisma/client%22%3B%0A%20%20%60%60%60%0A%20%20But%20be%20aware%20that%20this%20can%20still%20fail%20if%20the%20CLI%27s%20working%20directory%20or%20module%20resolution%20context%20can%27t%20find%20the%20file.%20In%20that%20case%2C%20reverting%20to%20the%20default%20output%20is%20the%20most%20reliable%20fix%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/2207%29%5D.%0A%0A-%20Avoid%20using%20TypeScript%20path%20aliases%20in%20your%20BetterAuth%20config%2C%20as%20the%20CLI%20uses%20%60jiti%60%20for%20module%20loading%2C%20which%20does%20not%20resolve%20aliases%20unless%20your%20%60tsconfig.json%60%20is%20perfectly%20configured%20and%20accessible%20from%20the%20CLI%27s%20working%20directory%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6373%29%5D.%0A%0A-%20Make%20sure%20your%20%60auth%60%20instance%20is%20exported%20as%20a%20named%20export%20%28%60export%20const%20auth%20%3D%20...%60%29%2C%20not%20a%20default%20export%2C%20so%20the%20CLI%20can%20find%20it%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4670%29%5D.%0A%0A-%20If%20you%20still%20see%20the%20error%20after%20these%20changes%2C%20try%20clearing%20your%20npm%20cache%20and%20reinstalling%20dependencies.%0A%0AThere%20are%20also%20some%20known%20compatibility%20issues%20between%20BetterAuth%20CLI%20and%20Prisma%20v7%2C%20especially%20around%20custom%20output%20paths%20and%20schema%20changes.%20Until%20full%20support%20lands%2C%20using%20the%20default%20Prisma%20client%20location%20is%20the%20safest%20approach%20%5B%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6469%29%5D.%0A%0ALet%20me%20know%20if%20you%20need%20help%20with%20a%20specific%20%60schema.prisma%60%20config%20or%20project%20structure%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/7033)
Author
Owner

@Rayan-Allali commented on GitHub (Dec 28, 2025):

using import { PrismaClient } from "@prisma/client"; throw the same error and i follow this source it was suggesting to use the generated prisma client :

I found the issue replace import { PrismaClient } from "@/generated/prisma/client"; by import { PrismaClient } from "../../generated/prisma/client"; (don't use @ or ~)

<!-- gh-comment-id:3694311030 --> @Rayan-Allali commented on GitHub (Dec 28, 2025): using `import { PrismaClient } from "@prisma/client";` throw the same error and i follow this [source](url) it was suggesting to use the generated prisma client : > I found the issue replace import { PrismaClient } from "@/generated/prisma/client"; by import { PrismaClient } from "../../generated/prisma/client"; (don't use @ or ~)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 28, 2025):

This is a known limitation with the BetterAuth CLI: it can't resolve TypeScript path aliases like @/generated/prisma/client because it uses the jiti loader, which doesn't support aliases unless your tsconfig.json is perfectly configured and accessible from the CLI's working directory. That's why the workaround is to use a relative import path (like ../../generated/prisma/client) instead of an alias—this lets the CLI find the generated Prisma client as long as the path is correct and the file exists.

However, if importing from both @prisma/client and a relative path still throws MODULE_NOT_FOUND, it's likely because the Prisma client isn't being generated where the CLI expects, or the CLI's working directory doesn't match your project structure. The most reliable fix is to remove the output field from your Prisma generator in schema.prisma, regenerate the client, and use the default import (@prisma/client)—this consistently works with BetterAuth CLI in all environments. If you must use a custom output path, double-check the relative path and ensure the generated files exist at that location before running the CLI.

For more details and community discussion, see this issue and this explanation.

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

<!-- gh-comment-id:3694313111 --> @dosubot[bot] commented on GitHub (Dec 28, 2025): <!-- Answer --> This is a known limitation with the BetterAuth CLI: it can't resolve TypeScript path aliases like `@/generated/prisma/client` because it uses the `jiti` loader, which doesn't support aliases unless your `tsconfig.json` is perfectly configured and accessible from the CLI's working directory. That's why the workaround is to use a relative import path (like `../../generated/prisma/client`) instead of an alias—this lets the CLI find the generated Prisma client as long as the path is correct and the file exists. However, if importing from both `@prisma/client` and a relative path still throws `MODULE_NOT_FOUND`, it's likely because the Prisma client isn't being generated where the CLI expects, or the CLI's working directory doesn't match your project structure. The most reliable fix is to remove the `output` field from your Prisma generator in `schema.prisma`, regenerate the client, and use the default import (`@prisma/client`)—this consistently works with BetterAuth CLI in all environments. If you must use a custom output path, double-check the relative path and ensure the generated files exist at that location before running the CLI. For more details and community discussion, see [this issue](https://github.com/better-auth/better-auth/issues/2207) and [this explanation](https://github.com/better-auth/better-auth/issues/6373). <!-- 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/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d5c41200-5fb9-4e8d-9ea8-41cf84d7b535?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%20is%20a%20known%20limitation%20with%20the%20BetterAuth%20CLI%3A%20it%20can%27t%20resolve%20TypeScript%20path%20aliases%20like%20%60%40/generated/prisma/client%60%20because%20it%20uses%20the%20%60jiti%60%20loader%2C%20which%20doesn%27t%20support%20aliases%20unless%20your%20%60tsconfig.json%60%20is%20perfectly%20configured%20and%20accessible%20from%20the%20CLI%27s%20working%20directory.%20That%27s%20why%20the%20workaround%20is%20to%20use%20a%20relative%20import%20path%20%28like%20%60../../generated/prisma/client%60%29%20instead%20of%20an%20alias%E2%80%94this%20lets%20the%20CLI%20find%20the%20generated%20Prisma%20client%20as%20long%20as%20the%20path%20is%20correct%20and%20the%20file%20exists.%20%0A%0AHowever%2C%20if%20importing%20from%20both%20%60%40prisma/client%60%20and%20a%20relative%20path%20still%20throws%20%60MODULE_NOT_FOUND%60%2C%20it%27s%20likely%20because%20the%20Prisma%20client%20isn%27t%20being%20generated%20where%20the%20CLI%20expects%2C%20or%20the%20CLI%27s%20working%20directory%20doesn%27t%20match%20your%20project%20structure.%20The%20most%20reliable%20fix%20is%20to%20remove%20the%20%60output%60%20field%20from%20your%20Prisma%20generator%20in%20%60schema.prisma%60%2C%20regenerate%20the%20client%2C%20and%20use%20the%20default%20import%20%28%60%40prisma/client%60%29%E2%80%94this%20consistently%20works%20with%20BetterAuth%20CLI%20in%20all%20environments.%20If%20you%20must%20use%20a%20custom%20output%20path%2C%20double-check%20the%20relative%20path%20and%20ensure%20the%20generated%20files%20exist%20at%20that%20location%20before%20running%20the%20CLI.%20%0A%0AFor%20more%20details%20and%20community%20discussion%2C%20see%20%5Bthis%20issue%5D%28https%3A//github.com/better-auth/better-auth/issues/2207%29%20and%20%5Bthis%20explanation%5D%28https%3A//github.com/better-auth/better-auth/issues/6373%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/7033)
Author
Owner

@Rayan-Allali commented on GitHub (Dec 28, 2025):

@dosubot i cant generate prisma client without the output field in schema.prisma
i tried generating prisma client => removing output from schema => importing the generating client in auth.ts => run pnpx @better-auth/cli generate but still it cant find prisma client

<!-- gh-comment-id:3694320148 --> @Rayan-Allali commented on GitHub (Dec 28, 2025): @dosubot i cant generate prisma client without the output field in schema.prisma i tried generating prisma client => removing output from schema => importing the generating client in auth.ts => run ` pnpx @better-auth/cli generate` but still it cant find prisma client
Author
Owner

@dosubot[bot] commented on GitHub (Dec 28, 2025):

With Prisma 7, the output field in the generator block is now required—the client is always generated outside node_modules, usually somewhere like src/generated/prisma. You must import PrismaClient from the actual generated location (e.g., import { PrismaClient } from "../../generated/prisma/client") and not from @prisma/client, which no longer works with custom outputs in Prisma 7. Removing the output field is not supported in Prisma 7 and will prevent client generation entirely, which is why you can't generate the client without it and why the CLI can't find it if you try.

To make BetterAuth CLI work with Prisma 7, double-check these points:

  • Your schema.prisma generator block must include output = "../src/generated/prisma" (or wherever you want the client).
  • After running prisma generate, confirm that the generated client exists at that path.
  • In your BetterAuth config, import PrismaClient using a relative path that matches the generated location (not a path alias).
  • Run the CLI from your project root so relative paths resolve correctly.

If you still get MODULE_NOT_FOUND, check that your tsconfig.json doesn't use path aliases for the Prisma client import, and that the generated files exist at the import path. If you have a monorepo or non-standard structure, you may need to adjust the CLI working directory or use a symlink to node_modules/@prisma/client as a workaround, but the most reliable approach is to use a relative import matching the generated output and run everything from the project root.

This is a breaking change in Prisma 7 and affects all tools that expect the client in node_modules. More details and workarounds are discussed here: Prisma 7 output requirement and import changes and BetterAuth CLI custom output issues.

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

<!-- gh-comment-id:3694324390 --> @dosubot[bot] commented on GitHub (Dec 28, 2025): <!-- Answer --> With Prisma 7, the output field in the generator block is now required—the client is always generated outside node_modules, usually somewhere like src/generated/prisma. You must import PrismaClient from the actual generated location (e.g., import { PrismaClient } from "../../generated/prisma/client") and not from @prisma/client, which no longer works with custom outputs in Prisma 7. Removing the output field is not supported in Prisma 7 and will prevent client generation entirely, which is why you can't generate the client without it and why the CLI can't find it if you try. To make BetterAuth CLI work with Prisma 7, double-check these points: - Your schema.prisma generator block must include output = "../src/generated/prisma" (or wherever you want the client). - After running prisma generate, confirm that the generated client exists at that path. - In your BetterAuth config, import PrismaClient using a relative path that matches the generated location (not a path alias). - Run the CLI from your project root so relative paths resolve correctly. If you still get MODULE_NOT_FOUND, check that your tsconfig.json doesn't use path aliases for the Prisma client import, and that the generated files exist at the import path. If you have a monorepo or non-standard structure, you may need to adjust the CLI working directory or use a symlink to node_modules/@prisma/client as a workaround, but the most reliable approach is to use a relative import matching the generated output and run everything from the project root. This is a breaking change in Prisma 7 and affects all tools that expect the client in node_modules. More details and workarounds are discussed here: [Prisma 7 output requirement and import changes](https://github.com/better-auth/better-auth/pull/6599) and [BetterAuth CLI custom output issues](https://github.com/better-auth/better-auth/issues/4670). <!-- 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/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/76478ef2-4e6b-49bd-ab37-2b175f1abbf9?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=With%20Prisma%207%2C%20the%20output%20field%20in%20the%20generator%20block%20is%20now%20required%E2%80%94the%20client%20is%20always%20generated%20outside%20node_modules%2C%20usually%20somewhere%20like%20src/generated/prisma.%20You%20must%20import%20PrismaClient%20from%20the%20actual%20generated%20location%20%28e.g.%2C%20import%20%7B%20PrismaClient%20%7D%20from%20%22../../generated/prisma/client%22%29%20and%20not%20from%20%40prisma/client%2C%20which%20no%20longer%20works%20with%20custom%20outputs%20in%20Prisma%207.%20Removing%20the%20output%20field%20is%20not%20supported%20in%20Prisma%207%20and%20will%20prevent%20client%20generation%20entirely%2C%20which%20is%20why%20you%20can%27t%20generate%20the%20client%20without%20it%20and%20why%20the%20CLI%20can%27t%20find%20it%20if%20you%20try.%0A%0ATo%20make%20BetterAuth%20CLI%20work%20with%20Prisma%207%2C%20double-check%20these%20points%3A%0A-%20Your%20schema.prisma%20generator%20block%20must%20include%20output%20%3D%20%22../src/generated/prisma%22%20%28or%20wherever%20you%20want%20the%20client%29.%0A-%20After%20running%20prisma%20generate%2C%20confirm%20that%20the%20generated%20client%20exists%20at%20that%20path.%0A-%20In%20your%20BetterAuth%20config%2C%20import%20PrismaClient%20using%20a%20relative%20path%20that%20matches%20the%20generated%20location%20%28not%20a%20path%20alias%29.%0A-%20Run%20the%20CLI%20from%20your%20project%20root%20so%20relative%20paths%20resolve%20correctly.%0A%0AIf%20you%20still%20get%20MODULE_NOT_FOUND%2C%20check%20that%20your%20tsconfig.json%20doesn%27t%20use%20path%20aliases%20for%20the%20Prisma%20client%20import%2C%20and%20that%20the%20generated%20files%20exist%20at%20the%20import%20path.%20If%20you%20have%20a%20monorepo%20or%20non-standard%20structure%2C%20you%20may%20need%20to%20adjust%20the%20CLI%20working%20directory%20or%20use%20a%20symlink%20to%20node_modules/%40prisma/client%20as%20a%20workaround%2C%20but%20the%20most%20reliable%20approach%20is%20to%20use%20a%20relative%20import%20matching%20the%20generated%20output%20and%20run%20everything%20from%20the%20project%20root.%0A%0AThis%20is%20a%20breaking%20change%20in%20Prisma%207%20and%20affects%20all%20tools%20that%20expect%20the%20client%20in%20node_modules.%20More%20details%20and%20workarounds%20are%20discussed%20here%3A%20%5BPrisma%207%20output%20requirement%20and%20import%20changes%5D%28https%3A//github.com/better-auth/better-auth/pull/6599%29%20and%20%5BBetterAuth%20CLI%20custom%20output%20issues%5D%28https%3A//github.com/better-auth/better-auth/issues/4670%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/7033)
Author
Owner

@Rayan-Allali commented on GitHub (Dec 28, 2025):

Yeah it is still throwing the same issue

<!-- gh-comment-id:3694564533 --> @Rayan-Allali commented on GitHub (Dec 28, 2025): Yeah it is still throwing the same issue
Author
Owner

@bytaesu commented on GitHub (Jan 9, 2026):

Hi @Rayan-Allali, I'm looking into this

<!-- gh-comment-id:3727597680 --> @bytaesu commented on GitHub (Jan 9, 2026): Hi @Rayan-Allali, I'm looking into this
Author
Owner

@BeInLife commented on GitHub (Jan 10, 2026):

Same issue, Cannot find module '@prisma/client/runtime/client'

<!-- gh-comment-id:3732308935 --> @BeInLife commented on GitHub (Jan 10, 2026): Same issue, Cannot find module '@prisma/client/runtime/client'
Author
Owner

@BeInLife commented on GitHub (Jan 10, 2026):

@Rayan-Allali
Even with custom path it works
you just need to install @prisma/client additionally
After that - it works perfectly

@bytaesu jfyi

<!-- gh-comment-id:3732463985 --> @BeInLife commented on GitHub (Jan 10, 2026): @Rayan-Allali Even with custom path it works you just need to install @prisma/client additionally After that - it works perfectly @bytaesu jfyi
Author
Owner

@Rayan-Allali commented on GitHub (Jan 10, 2026):

@BeInLife for me Prisma client was already installed

<!-- gh-comment-id:3732489583 --> @Rayan-Allali commented on GitHub (Jan 10, 2026): @BeInLife for me Prisma client was already installed
Author
Owner

@ussfranck commented on GitHub (Jan 18, 2026):

Hi 👋
I just went through this exact nightmare and I finally have a working, clean solution with:

  • NestJS latest
  • BetterAuth (latest)
  • Prisma v7 (latest)
  • Factory-based integration (no hack, no inline config, no magic)

The root problems are:

  • Prisma v7 now requires an adapter or accelerateUrl
  • BetterAuth + NestJS must be wired via a factory
  • You cannot instantiate Prisma the old way anymore
  • You must let NestJS own the PrismaService and inject it

I’ve created a full working template here:

👉 https://github.com/ussfranck/nestjs-better-auth-prisma

What this repo shows:

  • Proper PrismaService with adapter
  • Proper createAuth(prismaService) factory
  • Proper NestJS module wiring with useFactory
  • BetterAuth fully working: register, login, session, logout
  • Prisma v7 compatible
  • No hacks, no copying generated files, no CLI weirdness
  • Embedded common decorator like @Session() @AllowAnonymous() @OptionalAuth() etc.

If you’re stuck with:

PrismaClient needs to be constructed with adapter
or
Nest can't resolve dependencies
or
BetterAuth + Prisma v7 + NestJS not working

→ This repo solves all of it.

I lost a full day on this, so I hope this saves you some hours

<!-- gh-comment-id:3765570860 --> @ussfranck commented on GitHub (Jan 18, 2026): Hi 👋 I just went through this exact nightmare and I finally have a **working, clean solution** with: - NestJS latest - BetterAuth (latest) - Prisma v7 (latest) - Factory-based integration (no hack, no inline config, no magic) The root problems are: - Prisma v7 now **requires an adapter or accelerateUrl** - BetterAuth + NestJS **must be wired via a factory** - You **cannot** instantiate Prisma the old way anymore - You must let NestJS own the PrismaService and inject it I’ve created a **full working template** here: 👉 https://github.com/ussfranck/nestjs-better-auth-prisma What this repo shows: - ✅ Proper PrismaService with adapter - ✅ Proper `createAuth(prismaService)` factory - ✅ Proper NestJS module wiring with `useFactory` - ✅ BetterAuth fully working: register, login, session, logout - ✅ Prisma v7 compatible - ✅ No hacks, no copying generated files, no CLI weirdness - ✅ Embedded common decorator like @Session() @AllowAnonymous() @OptionalAuth() etc. If you’re stuck with: > PrismaClient needs to be constructed with adapter > or > Nest can't resolve dependencies > or > BetterAuth + Prisma v7 + NestJS not working → This repo solves all of it. I lost a full day on this, so I hope this saves you some hours
Author
Owner

@MirSameerIrfan commented on GitHub (Jan 28, 2026):

Hi 👋

I encountered the same MODULE_NOT_FOUND error and resolved it. Here's how:

Root Cause

The Better Auth CLI needs a relative import path (not a bare module path) when using a custom Prisma output directory.

Solution

1. Configure Prisma output (schema.prisma):

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

2. Generate Prisma client:

npx prisma generate

3. Fix the import in your Better Auth config:

INCORRECT:

import { PrismaClient } from "@prisma/client"
import { PrismaClient } from "generated/prisma/client"

CORRECT:

import { PrismaClient } from "../../generated/prisma/client"

Complete working config:

// src/features/auth/better-auth.ts
import { betterAuth } from "better-auth";
import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "../../generated/prisma/client"; // ← Use relative path
import { PrismaPg } from "@prisma/adapter-pg";

const adapter = new PrismaPg({
  connectionString: process.env.DATABASE_URL!,
});

const prisma = new PrismaClient({ adapter });

export const auth = betterAuth({
  database: prismaAdapter(prisma, { provider: "postgresql" }),
});

4. Run Better Auth CLI:

npx @better-auth/cli generate --config src/features/auth/better-auth.ts

Key Points

  • Use relative path from your config file to the Prisma client
  • Run prisma generate before Better Auth CLI
  • Path is relative to config file location, not project root

Full Documentation

Complete fix with troubleshooting guide: MirSameerIrfan/tanstack-start-better-auth-prisma

Hope this helps! 🚀

<!-- gh-comment-id:3808345982 --> @MirSameerIrfan commented on GitHub (Jan 28, 2026): Hi 👋 I encountered the same `MODULE_NOT_FOUND` error and resolved it. Here's how: ### Root Cause The Better Auth CLI needs a **relative import path** (not a bare module path) when using a custom Prisma output directory. ### Solution **1. Configure Prisma output (`schema.prisma`):** ```prisma generator client { provider = "prisma-client-js" output = "../generated/prisma" } ``` **2. Generate Prisma client:** ```bash npx prisma generate ``` **3. Fix the import in your Better Auth config:** **❌ INCORRECT:** ```typescript import { PrismaClient } from "@prisma/client" import { PrismaClient } from "generated/prisma/client" ``` **✅ CORRECT:** ```typescript import { PrismaClient } from "../../generated/prisma/client" ``` **Complete working config:** ```typescript // src/features/auth/better-auth.ts import { betterAuth } from "better-auth"; import { prismaAdapter } from "better-auth/adapters/prisma"; import { PrismaClient } from "../../generated/prisma/client"; // ← Use relative path import { PrismaPg } from "@prisma/adapter-pg"; const adapter = new PrismaPg({ connectionString: process.env.DATABASE_URL!, }); const prisma = new PrismaClient({ adapter }); export const auth = betterAuth({ database: prismaAdapter(prisma, { provider: "postgresql" }), }); ``` **4. Run Better Auth CLI:** ```bash npx @better-auth/cli generate --config src/features/auth/better-auth.ts ``` ### Key Points - ✅ Use relative path from your config file to the Prisma client - ✅ Run `prisma generate` before Better Auth CLI - ✅ Path is relative to config file location, not project root ### Full Documentation Complete fix with troubleshooting guide: **[MirSameerIrfan/tanstack-start-better-auth-prisma](https://github.com/MirSameerIrfan/tanstack-start-better-auth-prisma)** Hope this helps! 🚀
Author
Owner

@Ripper1028 commented on GitHub (Mar 7, 2026):

The above solved one problem, the next issue i had was I had to install better Auth/ prisma adapter? I thought that got installed with better Auth, or the adapter i got with prisma was the adapter I needed.

<!-- gh-comment-id:4015223166 --> @Ripper1028 commented on GitHub (Mar 7, 2026): The above solved one problem, the next issue i had was I had to install better Auth/ prisma adapter? I thought that got installed with better Auth, or the adapter i got with prisma was the adapter I needed.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10707