[GH-ISSUE #3762] CLI does not correctly resolve tsconfig references for path aliases #9715

Closed
opened 2026-04-13 05:23:00 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @ericc-ch on GitHub (Aug 3, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3762

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Note that the config file must contain imports that are using tsconfig path aliases

My tsconfig.json

{
  "compilerOptions": {
    "target": "ES2022",
    "skipLibCheck": true,
    "allowJs": true,

    "module": "ES2022",
    "moduleResolution": "bundler",
    "erasableSyntaxOnly": true,
    "verbatimModuleSyntax": true,
    "noEmit": true,

    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "exactOptionalPropertyTypes": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedSideEffectImports": true,

    "types": ["./worker-configuration.d.ts"],

    "plugins": [
      {
        "name": "@effect/language-service"
      }
    ]
  },

  "references": [
    { "path": "./tsconfig.app.json" },
    { "path": "./tsconfig.test.json" },
    { "path": "./tsconfig.node.json" }
  ],

  "files": []
}

The aliases are written in tsconfig.app.json:

{
  "extends": "./tsconfig.json",

  "compilerOptions": {
    "composite": true,

    "lib": ["DOM", "DOM.Iterable", "ES2022"],
    "jsx": "react-jsx",

    "esModuleInterop": true,
    "resolveJsonModule": true,

    "types": ["vite/client", "@vitest/browser/providers/playwright"],

    "baseUrl": ".",
    "rootDirs": [".", "./.react-router/types"],
    "paths": {
      "~/*": ["./src/*"]
    }
  },

  "include": [
    ".react-router/types/**/*",
    "src/**/*",
    "workers/**/*",
    "worker-configuration.d.ts"
  ],
  "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"]
}

Current vs. Expected behavior

When I run CLI to generate the schema:

$ bunx @better-auth/cli generate --config ./src/services/auth.ts
2025-08-03T02:34:19.019Z ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module '~/database/schema/_schema'
Require stack:
- /home/erickc/Documents/projects/sides/starter-web/src/services/database.ts
    at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15)
    at Function.resolve (node:internal/modules/helpers:145:19)
    at jitiResolve (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:190064)
    at jitiRequire (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:192130)
    at import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:202951)
    at /home/erickc/Documents/projects/sides/starter-web/src/services/database.ts:4:21
    at async import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:202945)
    at async /home/erickc/Documents/projects/sides/starter-web/src/services/auth.ts:5:17
    at async Function.import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:202945)
    at async resolveConfig (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/c12/dist/shared/c12.PQMoYrit.mjs:346:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/erickc/Documents/projects/sides/starter-web/src/services/database.ts'
  ]
}

The CLI should find the tsconfigs defined in references and resolve them as well

What version of Better Auth are you using?

Latest version of @better-auth/cli

Provide environment information

- OS: Linux 6.15.7-arch1-1
- Browser: not applicable

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

Other

Auth config (if applicable)

auth.ts


import { betterAuth } from "better-auth"
import { drizzleAdapter, type DB } from "better-auth/adapters/drizzle"
import { Effect } from "effect"

import { Database } from "./database"

export class Auth extends Effect.Service<Auth>()("service/Auth", {
  effect: Effect.gen(function* () {
    const db = yield* Database
    return betterAuth({
      database: drizzleAdapter(db, { provider: "sqlite" }),
    })
  }),
}) {}

// Fake auth config so better-auth can resolve it

const fakeDB: DB = {}

export const auth = betterAuth({
  database: drizzleAdapter(fakeDB, { provider: "sqlite" }),
})



database.ts


import * as Drizzle from "@effect/sql-drizzle/Sqlite"
import { Effect } from "effect"

import { schema } from "~/database/schema/_schema"

export class Database extends Effect.Service<Database>()("service/Database", {
  effect: Drizzle.make({
    schema: schema,
  }),
}) {}

Additional context

No response

Originally created by @ericc-ch on GitHub (Aug 3, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3762 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Note that the config file must contain imports that are using tsconfig path aliases My `tsconfig.json` ```jsonc { "compilerOptions": { "target": "ES2022", "skipLibCheck": true, "allowJs": true, "module": "ES2022", "moduleResolution": "bundler", "erasableSyntaxOnly": true, "verbatimModuleSyntax": true, "noEmit": true, "strict": true, "noUnusedLocals": true, "noUnusedParameters": true, "exactOptionalPropertyTypes": true, "noFallthroughCasesInSwitch": true, "noUncheckedSideEffectImports": true, "types": ["./worker-configuration.d.ts"], "plugins": [ { "name": "@effect/language-service" } ] }, "references": [ { "path": "./tsconfig.app.json" }, { "path": "./tsconfig.test.json" }, { "path": "./tsconfig.node.json" } ], "files": [] } ``` The aliases are written in `tsconfig.app.json`: ```jsonc { "extends": "./tsconfig.json", "compilerOptions": { "composite": true, "lib": ["DOM", "DOM.Iterable", "ES2022"], "jsx": "react-jsx", "esModuleInterop": true, "resolveJsonModule": true, "types": ["vite/client", "@vitest/browser/providers/playwright"], "baseUrl": ".", "rootDirs": [".", "./.react-router/types"], "paths": { "~/*": ["./src/*"] } }, "include": [ ".react-router/types/**/*", "src/**/*", "workers/**/*", "worker-configuration.d.ts" ], "exclude": ["src/**/*.test.ts", "src/**/*.test.tsx"] } ``` ### Current vs. Expected behavior When I run CLI to generate the schema: ``` $ bunx @better-auth/cli generate --config ./src/services/auth.ts 2025-08-03T02:34:19.019Z ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module '~/database/schema/_schema' Require stack: - /home/erickc/Documents/projects/sides/starter-web/src/services/database.ts at Function._resolveFilename (node:internal/modules/cjs/loader:1401:15) at Function.resolve (node:internal/modules/helpers:145:19) at jitiResolve (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:190064) at jitiRequire (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:192130) at import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:202951) at /home/erickc/Documents/projects/sides/starter-web/src/services/database.ts:4:21 at async import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:202945) at async /home/erickc/Documents/projects/sides/starter-web/src/services/auth.ts:5:17 at async Function.import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:202945) at async resolveConfig (file:///tmp/bunx-1000-@better-auth/cli@latest/node_modules/c12/dist/shared/c12.PQMoYrit.mjs:346:18) { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/erickc/Documents/projects/sides/starter-web/src/services/database.ts' ] } ``` The CLI should find the tsconfigs defined in references and resolve them as well ### What version of Better Auth are you using? Latest version of @better-auth/cli ### Provide environment information ```bash - OS: Linux 6.15.7-arch1-1 - Browser: not applicable ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript auth.ts import { betterAuth } from "better-auth" import { drizzleAdapter, type DB } from "better-auth/adapters/drizzle" import { Effect } from "effect" import { Database } from "./database" export class Auth extends Effect.Service<Auth>()("service/Auth", { effect: Effect.gen(function* () { const db = yield* Database return betterAuth({ database: drizzleAdapter(db, { provider: "sqlite" }), }) }), }) {} // Fake auth config so better-auth can resolve it const fakeDB: DB = {} export const auth = betterAuth({ database: drizzleAdapter(fakeDB, { provider: "sqlite" }), }) database.ts import * as Drizzle from "@effect/sql-drizzle/Sqlite" import { Effect } from "effect" import { schema } from "~/database/schema/_schema" export class Database extends Effect.Service<Database>()("service/Database", { effect: Drizzle.make({ schema: schema, }), }) {} ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 05:23:00 -05:00
Author
Owner

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

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

The Better Auth CLI does not currently support resolving TypeScript path aliases defined in referenced or extended tsconfig files (like your tsconfig.app.json). This is a known limitation and is the reason for the Cannot find module '~/database/schema/_schema' error—Node.js and the CLI do not interpret TypeScript path aliases at runtime, and the CLI's config loader does not merge or resolve aliases from referenced configs [issue #343] [issue #3549].

Workarounds include creating a temporary or simplified auth.ts file that avoids path aliases, copying the config file to the project root, or restructuring imports so that files used by the CLI do not use aliases [issue #3549] [issue #794]. Running the CLI with tools like tsx does not resolve this, since the CLI itself lacks alias resolution logic [issue #3211].

There are open feature requests for a --tsConfig flag or better tsconfig-paths integration, but as of now, no such feature has shipped [issue #874].

You can track progress or add your use case to these threads:

For now, the most reliable approach is to avoid path aliases in files consumed by the CLI or use a minimal config file just for schema generation.

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:3146932813 --> @dosubot[bot] commented on GitHub (Aug 3, 2025): <!-- Greeting --> Hi @ericc-ch! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The Better Auth CLI does not currently support resolving TypeScript path aliases defined in referenced or extended tsconfig files (like your `tsconfig.app.json`). This is a known limitation and is the reason for the `Cannot find module '~/database/schema/_schema'` error—Node.js and the CLI do not interpret TypeScript path aliases at runtime, and the CLI's config loader does not merge or resolve aliases from referenced configs [[issue #343]](https://github.com/better-auth/better-auth/issues/343) [[issue #3549]](https://github.com/better-auth/better-auth/issues/3549). Workarounds include creating a temporary or simplified `auth.ts` file that avoids path aliases, copying the config file to the project root, or restructuring imports so that files used by the CLI do not use aliases [[issue #3549]](https://github.com/better-auth/better-auth/issues/3549) [[issue #794]](https://github.com/better-auth/better-auth/issues/794). Running the CLI with tools like `tsx` does not resolve this, since the CLI itself lacks alias resolution logic [[issue #3211]](https://github.com/better-auth/better-auth/issues/3211). There are open feature requests for a `--tsConfig` flag or better tsconfig-paths integration, but as of now, no such feature has shipped [[issue #874]](https://github.com/better-auth/better-auth/issues/874). You can track progress or add your use case to these threads: - [CLI does not resolve path aliases in tsconfig references (#343)](https://github.com/better-auth/better-auth/issues/343) - [CLI fails with path aliases in referenced tsconfig files (#3549)](https://github.com/better-auth/better-auth/issues/3549) - [Feature request for custom tsconfig support (#874)](https://github.com/better-auth/better-auth/issues/874) For now, the most reliable approach is to avoid path aliases in files consumed by the CLI or use a minimal config file just for schema generation. <!-- 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/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1b0ceca4-f25d-4532-ba90-f166ec6f4a23?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/3762)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9715