[GH-ISSUE #795] bunx @better-auth/cli generate should allow import 'server-only' #8437

Closed
opened 2026-04-13 03:30:24 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @ftzi on GitHub (Dec 7, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/795

Is your feature request related to a problem? Please describe.
Currently, the bunx @better-auth/cli generate errors if the auth.ts file has the import 'server-only' :

[Better Auth] ERROR Couldn't read your auth config. This module cannot be imported from a Client Component module. It should only be used from a Server Component.

Describe the solution you'd like
I don't know if it's possible to overcome this, but I would like if the generate tool didn't error if the auth.ts file have this import.

Describe alternatives you've considered
Don't use this import 'server-only'. But I would like to for clarity!

Additional context
https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#keeping-server-only-code-out-of-the-client-environment

Originally created by @ftzi on GitHub (Dec 7, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/795 **Is your feature request related to a problem? Please describe.** Currently, the `bunx @better-auth/cli generate` errors if the `auth.ts` file has the `import 'server-only'` : `[Better Auth] ERROR Couldn't read your auth config. This module cannot be imported from a Client Component module. It should only be used from a Server Component.` **Describe the solution you'd like** I don't know if it's possible to overcome this, but I would like if the `generate` tool didn't error if the `auth.ts` file have this import. **Describe alternatives you've considered** Don't use this `import 'server-only'`. But I would like to for clarity! **Additional context** https://nextjs.org/docs/app/building-your-application/rendering/composition-patterns#keeping-server-only-code-out-of-the-client-environment
GiteaMirror added the locked label 2026-04-13 03:30:24 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 12, 2025):

Hi, @ftzi. I'm Dosu, and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale.

Issue Summary:

  • Enhancement request for bunx @better-auth/cli generate tool.
  • You want to use import 'server-only' in auth.ts without errors.
  • The error currently restricts its use to Server Components.
  • No comments or additional activity have been made on this issue.

Next Steps:

  • Is this issue still relevant to the latest version of the better-auth repository? If so, please comment to keep the discussion open.
  • If there is no further activity, the issue will be automatically closed in 7 days.

Thank you for your understanding and contribution!

<!-- gh-comment-id:2967416270 --> @dosubot[bot] commented on GitHub (Jun 12, 2025): Hi, @ftzi. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog. I'm marking this issue as stale. **Issue Summary:** - Enhancement request for `bunx @better-auth/cli generate` tool. - You want to use `import 'server-only'` in `auth.ts` without errors. - The error currently restricts its use to Server Components. - No comments or additional activity have been made on this issue. **Next Steps:** - Is this issue still relevant to the latest version of the better-auth repository? If so, please comment to keep the discussion open. - If there is no further activity, the issue will be automatically closed in 7 days. Thank you for your understanding and contribution!
Author
Owner

@ping-maxwell commented on GitHub (Aug 11, 2025):

This is difficult, since the package is basically like 5 lines of code and the only logic is a throw new Error.
So whenever you import it, it will always throw an error. I assume frameworks like Next don't get this on the server via some bundling tricks or something else, but for us that's not really an option.

I recommend commenting out the server-only import until you're done with the CLI, or have a separate duplicate auth config specific for the purpose of the CLI to not run into these types of issues.

We don't have intentions of bundling/modifying the auth.ts at runtime at this time, so please use a work-around such as the ones I just suggested.

<!-- gh-comment-id:3175929920 --> @ping-maxwell commented on GitHub (Aug 11, 2025): This is difficult, since the package is basically like 5 lines of code and the only logic is a `throw new Error`. So whenever you import it, it will always throw an error. I assume frameworks like Next don't get this on the server via some bundling tricks or something else, but for us that's not really an option. I recommend commenting out the server-only import until you're done with the CLI, or have a separate duplicate auth config specific for the purpose of the CLI to not run into these types of issues. We don't have intentions of bundling/modifying the auth.ts at runtime at this time, so please use a work-around such as the ones I just suggested.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8437