path aliases not resolving correctly for cli #144

Closed
opened 2026-03-13 07:35:11 -05:00 by GiteaMirror · 0 comments
Owner

Originally created by @nlynzaad on GitHub (Oct 26, 2024).

Hi

First off thank you for the effort everyone is putting into this library. There is definitely a need for alternative local auth libraries.

While playing around and trying to setup better-auth in a t3app I could not run the generate command when using the path aliases setup in tsconfig.json. This was addressed in the #80 but this doesn't seem to have resolved the issue in full.

Describe the bug
When using custom path aliases, the cli cannot correctly resolve the imports.

To Reproduce
a minimal reproduction with nextjs and prisma was created on CodeSandbox

the following steps was taken to create the reproduction:

  1. create new nextjs app
  2. install prisma using sqlite as datasource.
  3. install better-auth
  4. create new folder "server" in the root of the project
  5. add the following alias to the tsconfig: "@server/": ["./server/"]
  6. create 2 folders in the server folder. "auth" and "db"
  7. create prismaClient.ts file in db folder. Create and export prisma client in this file
  8. create auth.ts file in the auth folder and setup auth config in the auth.ts using imported prisma client from "@server/db/prismaClient"
  9. run "npx @better-auth/cli@latest generate --config server/auth/auth.ts"

Expected behavior
schema should be generated and added to the schema.prisma file in "./prisma" folder as this is the default output path

Actual behavior
cli reports an error: "Couldn't read your config".

Additional context
I've looked through get-config.ts and the getPathAliases function doesn't seem to correctly address the problem:

  1. it hardcodes the path to "../" for all aliases
  2. it assumes the alias is only one character long for example "@"
  3. it does not cater for the different aliases that can be used according the typescript documentation.
  4. it does not take into account the base url in tsconfig.json.
  5. I have forked the repo and made alterations and will post a PR shortly
Originally created by @nlynzaad on GitHub (Oct 26, 2024). Hi First off thank you for the effort everyone is putting into this library. There is definitely a need for alternative local auth libraries. While playing around and trying to setup better-auth in a t3app I could not run the generate command when using the path aliases setup in tsconfig.json. This was addressed in the #80 but this doesn't seem to have resolved the issue in full. **Describe the bug** When using custom path aliases, the cli cannot correctly resolve the imports. **To Reproduce** a minimal reproduction with nextjs and prisma was created on [CodeSandbox](https://codesandbox.io/p/devbox/jvgshq) the following steps was taken to create the reproduction: 1. create new nextjs app 2. install prisma using sqlite as datasource. 3. install better-auth 4. create new folder "server" in the root of the project 5. add the following alias to the tsconfig: "@server/*": ["./server/*"] 6. create 2 folders in the server folder. "auth" and "db" 7. create prismaClient.ts file in db folder. Create and export prisma client in this file 8. create auth.ts file in the auth folder and setup auth config in the auth.ts using imported prisma client from "@server/db/prismaClient" 9. run "npx @better-auth/cli@latest generate --config server/auth/auth.ts" **Expected behavior** schema should be generated and added to the schema.prisma file in "./prisma" folder as this is the default output path **Actual behavior** cli reports an error: "Couldn't read your config". **Additional context** I've looked through get-config.ts and the getPathAliases function doesn't seem to correctly address the problem: 1) it hardcodes the path to "../" for all aliases 2) it assumes the alias is only one character long for example "@" 3) it does not cater for the different aliases that can be used according the typescript [documentation](https://www.typescriptlang.org/tsconfig/#paths). 4) it does not take into account the base url in tsconfig.json. 5) I have forked the repo and made alterations and will post a PR shortly
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#144