Better Auth Package Exports#
Both better-auth and @better-auth/oauth-provider use a fully explicit Node.js exports map with ESM-only output built by tsdown. Every subpath is listed individually — there is no wildcard catch-all — and each entry carries three conditions: dev-source, types, and default.
better-auth Export Map#
packages/better-auth/package.json (current version: 1.6.25) publishes only the dist/ folder and exposes 40+ named subpaths. Key ones:
| Subpath | Source entry | Notes |
|---|---|---|
. | src/index.ts | Main server entrypoint |
./minimal | src/auth/minimal.ts | Lightweight server build |
./client | src/client/index.ts | Browser/universal client |
./client/plugins | src/client/plugins/index.ts | Client plugin registry |
./types | src/types/index.ts | Public type-only export |
./plugins | src/plugins/index.ts | All server plugins (bundle) |
./plugins/<name> | src/plugins/<name>/index.ts | Per-plugin subpath (20+) |
./adapters/<adapter> | src/adapters/<adapter>/index.ts | Prisma, Drizzle, MongoDB, Memory |
./react, ./vue, ./svelte, ./solid, ./lynx | Framework client integrations | |
./next-js, ./svelte-kit, ./solid-start, ./tanstack-start | Server framework integrations | |
./db, ./db/adapter, ./db/adapter/minimal, ./db/migration | Database utilities | |
./api, ./crypto, ./cookies, ./oauth2 | Internal utilities surfaced for advanced use | |
./test | src/test-utils/index.ts | Test helpers |
./plugins/mcp/client, ./plugins/mcp/client/adapters | MCP client integration |
All compiled types use .d.mts declarations matching .mjs runtime files.
A parallel typesVersions block maps the same subpaths for older TypeScript versions that don't read exports.types.
The package is declared "type": "module" and "sideEffects": false.
@better-auth/oauth-provider Export Map#
packages/oauth-provider/package.json exposes three subpaths:
| Subpath | File | Purpose |
|---|---|---|
. | src/index.ts → dist/index.mjs | Server plugin (oauthProvider, metadata exports, all types) |
./client | src/client.ts → dist/client.mjs | oauthProviderClient — browser-side plugin |
./resource-client | src/client-resource.ts → dist/client-resource.mjs | Resource server client |
The root src/index.ts re-exports everything from ./types via export type * from "./types".
./client entry#
oauthProviderClient is a BetterAuthClientPlugin that injects an oauth_query body field into non-GET/DELETE requests when window.location.search is present. It infers the server plugin's types via $InferServerPlugin: {} as ReturnType<typeof oauthProvider>.
The dev-source Export Condition#
Every subpath in both packages includes a dev-source condition pointing to the original .ts source file (e.g., "dev-source": "./src/index.ts"). This is a custom TypeScript customConditions entry (set in the workspace-level tsconfig.base.json) that lets IDEs and TypeScript resolve "jump-to-definition" directly to source rather than compiled declarations. It has no effect at runtime or during normal consumer builds.
Non-Portable Type Export Fix (PR #9406)#
Problem: Downstream projects that re-export oauthProvider and ran tsc --emitDeclarationOnly received TS2742 errors — TypeScript could not portably reference helper types (AuthMethod, BearerMethodsSupported, GrantType, TokenEndpointAuthMethod) because they were used inside the public OAuthOptions interface but not re-exported from the package entrypoint.
Fix: PR #9406 added explicit export type { ... } re-exports for those four types from src/types/index.ts :
export type {
AuthMethod,
AuthServerMetadata,
BearerMethodsSupported,
GrantType,
OAuthClient,
OIDCMetadata,
ResourceServerMetadata,
TokenEndpointAuthMethod,
} from "./oauth";
Regression guard: The PR also converted the e2e smoke fixture from noEmit: true to emitDeclarationOnly: true so CI actually exercises declaration emission rather than just type-checking.
General rule: Any type that appears in a public API's function signature or interface must be re-exported from the package entrypoint. If it is only reachable through internal imports, TypeScript's declaration emitter will generate non-portable references that break consumers in composite/project-reference setups.
Key References#
packages/better-auth/package.json— full exports map and typesVersionspackages/oauth-provider/package.json— oauth-provider exports mappackages/oauth-provider/src/index.ts— root re-export barrelpackages/oauth-provider/src/types/index.ts— public type surfacepackages/oauth-provider/src/client.ts— client plugin- PR #9406 — non-portable type export fix