[GH-ISSUE #3788] @better-auth/cli generate is not working for demo/nextjs #18357

Closed
opened 2026-04-15 16:48:18 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @himself65 on GitHub (Aug 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3788

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

npx @better-auth/cli@latest generate --config ./lib/auth

Current vs. Expected behavior

2025-08-04T21:17:40.691Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in /Users/himself65/Code/better-auth/packages/better-auth/demo/nextjs/lib/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.

What version of Better Auth are you using?

latest

Provide environment information

- macOS

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

Package

Auth config (if applicable)


Additional context

No response

Originally created by @himself65 on GitHub (Aug 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3788 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce `npx @better-auth/cli@latest generate --config ./lib/auth` ### Current vs. Expected behavior ``` 2025-08-04T21:17:40.691Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in /Users/himself65/Code/better-auth/packages/better-auth/demo/nextjs/lib/auth.ts. Make sure to default export your auth instance or to export as a variable named auth. ``` ### What version of Better Auth are you using? latest ### Provide environment information ```bash - macOS ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 16:48:19 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 4, 2025):

The CLI expects your config file to export the auth instance as either a named export called auth or as a default export. Common causes for this error are: missing or incorrect exports, using path aliases like @ or ~ in imports (which aren't resolved outside Next.js), or referencing environment variables or modules that only exist at runtime or after a build step. The config file and all its imports must be directly importable by Node.js at CLI runtime—no framework-specific aliases or build-only modules are supported [1] [2] [3].

Checklist:

  • Make sure lib/auth.ts exports your auth instance like export const auth = betterAuth({...}) (no default export unless it's the same instance).
  • Avoid using path aliases (like @/lib/prisma) in your imports—use relative paths instead.
  • Ensure all dependencies and environment variables are available at CLI runtime.
  • If you reference any properties or modules that are undefined or fail to import, the CLI will show this error even if your export is correct [4].

To isolate the problem, try replacing your config with a minimal example:

import { betterAuth } from "better-auth";
export const auth = betterAuth({});

If this works, gradually add back your real config to find the breaking part. If you’re still stuck, sharing the contents of lib/auth.ts will help pinpoint the issue.

To reply, just mention @dosu.


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

<!-- gh-comment-id:3152446339 --> @dosubot[bot] commented on GitHub (Aug 4, 2025): <!-- Answer --> The CLI expects your config file to export the auth instance as either a named export called `auth` or as a default export. Common causes for this error are: missing or incorrect exports, using path aliases like `@` or `~` in imports (which aren't resolved outside Next.js), or referencing environment variables or modules that only exist at runtime or after a build step. The config file and all its imports must be directly importable by Node.js at CLI runtime—no framework-specific aliases or build-only modules are supported [[1]](https://github.com/better-auth/better-auth/issues/1215) [[2]](https://github.com/better-auth/better-auth/issues/2207) [[3]](https://github.com/better-auth/better-auth/issues/1766). Checklist: - Make sure `lib/auth.ts` exports your auth instance like `export const auth = betterAuth({...})` (no default export unless it's the same instance). - Avoid using path aliases (like `@/lib/prisma`) in your imports—use relative paths instead. - Ensure all dependencies and environment variables are available at CLI runtime. - If you reference any properties or modules that are undefined or fail to import, the CLI will show this error even if your export is correct [[4]](https://github.com/better-auth/better-auth/issues/3472). To isolate the problem, try replacing your config with a minimal example: ```typescript import { betterAuth } from "better-auth"; export const auth = betterAuth({}); ``` If this works, gradually add back your real config to find the breaking part. If you’re still stuck, sharing the contents of `lib/auth.ts` will help pinpoint the issue. <!-- 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/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/fce7ae67-baf1-4289-9632-ee24d58e179b?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/3788)
Author
Owner

@himself65 commented on GitHub (Aug 4, 2025):

realized that it's in the wrong pwd

<!-- gh-comment-id:3152515626 --> @himself65 commented on GitHub (Aug 4, 2025): realized that it's in the wrong pwd
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18357