[GH-ISSUE #4110] @better-auth/cli generate throws error with default export #18465

Closed
opened 2026-04-15 16:55:24 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @thejanasatan on GitHub (Aug 20, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4110

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Trying the following on better-auth: 1.3.7, and @better-auth/cli version 0.0.1.

npx @better-auth/cli@latest generate --config ./src/lib/server/auth.ts --output ./src/lib/server/db/auth-schema.ts

auth.ts

import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { database } from '$lib/server/db';

const authInstance = betterAuth({
	emailAndPassword: {
		enabled: true
	},
	database: drizzleAdapter(database, {
		provider: 'pg'
	})
});

export default authInstance;

I'm getting the following error when the auth instance is the default export:

2025-08-20T19:55:28.985Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in ./src/lib/server/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.

The error goes away if I export the instance as the preferred named export (export const auth = authInstance).

Framework: SvelteKit (2.22.0)

Current vs. Expected behavior

Expectation is that the generate command works consistently with either method of exporting the auth instance.

What version of Better Auth are you using?

1.3.7

System info

System:
    OS: macOS 15.6
    CPU: (10) arm64 Apple M1 Pro
    Memory: 2.56 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chrome: 139.0.7258.128
    Safari: 18.6

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

Package

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { database } from '$lib/server/db';

const authInstance = betterAuth({
	emailAndPassword: {
		enabled: true
	},
	database: drizzleAdapter(database, {
		provider: 'pg'
	})
});

export default authInstance;

Additional context

Trying the following on better-auth: 1.3.7, and @better-auth/cli version 0.0.1.

Originally created by @thejanasatan on GitHub (Aug 20, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4110 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Trying the following on `better-auth: 1.3.7`, and `@better-auth/cli` version `0.0.1`. ``` npx @better-auth/cli@latest generate --config ./src/lib/server/auth.ts --output ./src/lib/server/db/auth-schema.ts ``` auth.ts ```js import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { database } from '$lib/server/db'; const authInstance = betterAuth({ emailAndPassword: { enabled: true }, database: drizzleAdapter(database, { provider: 'pg' }) }); export default authInstance; ``` I'm getting the following error when the auth instance is the default export: ``` 2025-08-20T19:55:28.985Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in ./src/lib/server/auth.ts. Make sure to default export your auth instance or to export as a variable named auth. ``` The error goes away if I export the instance as the preferred named export (`export const auth = authInstance`). Framework: SvelteKit (2.22.0) ### Current vs. Expected behavior Expectation is that the generate command works consistently with either method of exporting the auth instance. ### What version of Better Auth are you using? 1.3.7 ### System info ```bash System: OS: macOS 15.6 CPU: (10) arm64 Apple M1 Pro Memory: 2.56 GB / 32.00 GB Shell: 5.9 - /bin/zsh Browsers: Chrome: 139.0.7258.128 Safari: 18.6 ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { database } from '$lib/server/db'; const authInstance = betterAuth({ emailAndPassword: { enabled: true }, database: drizzleAdapter(database, { provider: 'pg' }) }); export default authInstance; ``` ### Additional context Trying the following on `better-auth: 1.3.7`, and `@better-auth/cli` version `0.0.1`.
GiteaMirror added the lockedbug labels 2026-04-15 16:55:24 -05:00
Author
Owner

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

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

This is a known limitation: the Better Auth CLI generate command only reliably works when your auth instance is exported as a named export called auth (e.g., export const auth = betterAuth({...})). Despite the error message suggesting default exports are supported, multiple user reports and code review confirm that default exports do not work as expected, and the CLI prioritizes the named export auth.

To resolve this, use only a named export for your auth instance and avoid exporting both a named and a default export in the same file. This is also the pattern shown in all official documentation and examples.

If you need to reference your auth instance elsewhere, import it as a named import. This approach is the only reliable workaround until the CLI's handling of default exports is improved.

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:3207924316 --> @dosubot[bot] commented on GitHub (Aug 20, 2025): <!-- Greeting --> Hi @thejanasatan! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known limitation: the Better Auth CLI generate command only reliably works when your auth instance is exported as a named export called `auth` (e.g., `export const auth = betterAuth({...})`). Despite the error message suggesting default exports are supported, multiple user reports and code review confirm that default exports do not work as expected, and the CLI prioritizes the named export [`auth`](https://github.com/better-auth/better-auth/issues/1215#issuecomment-3067106225). To resolve this, use only a named export for your auth instance and avoid exporting both a named and a default export in the same file. This is also the pattern shown in all official documentation and examples. If you need to reference your auth instance elsewhere, import it as a named import. This approach is the only reliable workaround until the CLI's handling of default exports is improved. <!-- 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/374386d9-5cea-4217-95e7-74ff193e0eec?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/374386d9-5cea-4217-95e7-74ff193e0eec?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/374386d9-5cea-4217-95e7-74ff193e0eec?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/374386d9-5cea-4217-95e7-74ff193e0eec?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/374386d9-5cea-4217-95e7-74ff193e0eec?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/374386d9-5cea-4217-95e7-74ff193e0eec?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/374386d9-5cea-4217-95e7-74ff193e0eec?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/4110)
Author
Owner

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

what's your tsconfig?

<!-- gh-comment-id:3208286261 --> @himself65 commented on GitHub (Aug 20, 2025): what's your tsconfig?
Author
Owner

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

ok, I can see the error. trying to fix

<!-- gh-comment-id:3208287609 --> @himself65 commented on GitHub (Aug 20, 2025): ok, I can see the error. trying to fix
Author
Owner

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

c12 issue. Will give a patch

<!-- gh-comment-id:3208322385 --> @himself65 commented on GitHub (Aug 20, 2025): c12 issue. Will give a patch
Author
Owner

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

related: https://github.com/unjs/c12/issues/244

<!-- gh-comment-id:3208326695 --> @himself65 commented on GitHub (Aug 20, 2025): related: https://github.com/unjs/c12/issues/244
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18465