[GH-ISSUE #2252] generate in CLI fails with import using $ in SvelteKit #9115

Closed
opened 2026-04-13 04:27:59 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @DePasqualeOrg on GitHub (Apr 13, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2252

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

In auth.ts, include an import like this: import { db } from "$lib/server/drizzle";

Current vs. Expected behavior

Current: ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module '$lib/server/drizzle'

Expected: CLI should work with import using $.

What version of Better Auth are you using?

1.2.5

Provide environment information

OS: macOS 15

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

Backend

Auth config (if applicable)


Additional context

The generate command in the CLI only works when a relative path is used in auth.ts: import { db } from "./drizzle";

Originally created by @DePasqualeOrg on GitHub (Apr 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2252 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce In `auth.ts`, include an import like this: `import { db } from "$lib/server/drizzle";` ### Current vs. Expected behavior Current: `ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module '$lib/server/drizzle'` Expected: CLI should work with import using $. ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash OS: macOS 15 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context The `generate` command in the CLI only works when a relative path is used in `auth.ts`: `import { db } from "./drizzle";`
GiteaMirror added the locked label 2026-04-13 04:27:59 -05:00
Author
Owner

@aboudy98 commented on GitHub (Apr 13, 2025):

can you please provide more details

<!-- gh-comment-id:2799964568 --> @aboudy98 commented on GitHub (Apr 13, 2025): can you please provide more details
Author
Owner

@DePasqualeOrg commented on GitHub (Apr 13, 2025):

It's very simple, and just as I described: generate in the CLI fails when auth.ts includes imports using $ in SvelteKit. These imports are correct and work within SvelteKit.

<!-- gh-comment-id:2799966981 --> @DePasqualeOrg commented on GitHub (Apr 13, 2025): It's very simple, and just as I described: `generate` in the CLI fails when `auth.ts` includes imports using $ in SvelteKit. These imports are correct and work within SvelteKit.
Author
Owner

@Kinfe123 commented on GitHub (Apr 14, 2025):

we are using the generic file path convention to locate your file path

<!-- gh-comment-id:2800878105 --> @Kinfe123 commented on GitHub (Apr 14, 2025): we are using the generic file path convention to locate your file path
Author
Owner

@DePasqualeOrg commented on GitHub (Apr 14, 2025):

Yes, that's clear to me. But ideally users shouldn't be forced to change their code just for Better Auth. Using $lib in particular is idiomatic in SvelteKit. Would it be possible for Better Auth to correctly interpret these file paths?

<!-- gh-comment-id:2800916556 --> @DePasqualeOrg commented on GitHub (Apr 14, 2025): Yes, that's clear to me. But ideally users shouldn't be forced to change their code just for Better Auth. Using `$lib` in particular is idiomatic in SvelteKit. Would it be possible for Better Auth to correctly interpret these file paths?
Author
Owner

@Kinfe123 commented on GitHub (Apr 14, 2025):

Yeah, making the CLI more extendable would definitely help address those cases. But since the CLI setup is a one-time thing, you should be fine. That said, we might end up adding some bloat to handle different frameworks' file path conventions.

<!-- gh-comment-id:2801113896 --> @Kinfe123 commented on GitHub (Apr 14, 2025): Yeah, making the CLI more extendable would definitely help address those cases. But since the CLI setup is a one-time thing, you should be fine. That said, we might end up adding some bloat to handle different frameworks' file path conventions.
Author
Owner

@budivoogt commented on GitHub (Jun 24, 2025):

I ran into the same issue and agree with @DePasqualeOrg that adjusting pattern of imports for BetterAuth's CLI isn't optimal. Especially not when you're using dependency injection and need to refactor a container that imports many dependencies.

<!-- gh-comment-id:3001610424 --> @budivoogt commented on GitHub (Jun 24, 2025): I ran into the same issue and agree with @DePasqualeOrg that adjusting pattern of imports for BetterAuth's CLI isn't optimal. Especially not when you're using dependency injection and need to refactor a container that imports many dependencies.
Author
Owner

@rebasecase commented on GitHub (Jun 27, 2025):

we might end up adding some bloat to handle different frameworks' file path conventions.

Uh... have you seen the amount of "what if" features you already have?

You say this, also, yet you support import { env } from '$env/dynamic/private';

<!-- gh-comment-id:3014091741 --> @rebasecase commented on GitHub (Jun 27, 2025): >we might end up adding some bloat to handle different frameworks' file path conventions. Uh... have you seen the amount of "what if" features you already have? You say this, also, yet you support `import { env } from '$env/dynamic/private';`
Author
Owner

@rebasecase commented on GitHub (Jun 27, 2025):

@DePasqualeOrg as a workaround

tsx node_modules/@better-auth/cli/dist/index.mjs generate --config ./path/to/auth.ts

<!-- gh-comment-id:3014104708 --> @rebasecase commented on GitHub (Jun 27, 2025): @DePasqualeOrg as a workaround `tsx node_modules/@better-auth/cli/dist/index.mjs generate --config ./path/to/auth.ts`
Author
Owner

@amlcx commented on GitHub (Aug 16, 2025):

+1

currently running into the same issue. I know better-auth is framework agnostic, but basically going against each framework's conventions just so better-auth CLI can correctly infer paths is not optimal. Not to mention, there are some paths that are generated on the fly.

<!-- gh-comment-id:3193367210 --> @amlcx commented on GitHub (Aug 16, 2025): +1 currently running into the same issue. I know better-auth is framework agnostic, but basically going against each framework's conventions just so better-auth CLI can correctly infer paths is not optimal. Not to mention, there are some paths that are generated on the fly.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9115