[GH-ISSUE #3067] TypeScript Error: "The inferred type of this node exceeds the maximum length the compiler will serialize" when using admin and organization plugins together. #9458

Closed
opened 2026-04-13 04:55:48 -05:00 by GiteaMirror · 9 comments
Owner

Originally created by @harveylee on GitHub (Jun 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3067

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

import { betterAuth } from 'better-auth'
import { admin, organization } from 'better-auth/plugins'

export const auth = betterAuth({
  plugins: [admin(), organization()],
})

Typescript complains about auth:
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. ts(7056)

Current vs. Expected behavior

Current: Typescript error as above
Expected: No Typescript error

What version of Better Auth are you using?

1.2.9

Provide environment information

- OS: Windows 11 Home, v10.0.26100 Build 26100, running WSL2
- WSL2: Linux 6.6.87.1-microsoft-standard-WSL2
- Debian trixie

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

Backend

Auth config (if applicable)

See repro above

Additional context

  • Possibly related to https://github.com/better-auth/better-auth/issues/949
  • This issue does not occur in Better Auth v1.2.7 and starts to occur from v1.2.8-beta.1 onwards
  • This issue does not occur using either the Admin or the Organization plugins by themselves; the issue only occurs using them together
  • Tested with Typescript 5.8.3 as well as the 5.9.0-dev.20250617 nightly

tsconfig.json extract:

{
  "extends": "./node_modules/@tsconfig/bun/tsconfig.json",
  "compilerOptions": {
    "incremental": true,
    "composite": true,
    "lib": ["ESNext", "DOM", "DOM.Iterable"],
    "strict": true,
    "allowUnreachableCode": true,
    "noPropertyAccessFromIndexSignature": false,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "declaration": false,
    "emitDeclarationOnly": true,
    "noEmit": false,
    "isolatedModules": true,
    "skipLibCheck": true
  }
}
Originally created by @harveylee on GitHub (Jun 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3067 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```ts import { betterAuth } from 'better-auth' import { admin, organization } from 'better-auth/plugins' export const auth = betterAuth({ plugins: [admin(), organization()], }) ``` Typescript complains about `auth`: `The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. ts(7056)` ### Current vs. Expected behavior Current: Typescript error as above Expected: No Typescript error ### What version of Better Auth are you using? 1.2.9 ### Provide environment information ```bash - OS: Windows 11 Home, v10.0.26100 Build 26100, running WSL2 - WSL2: Linux 6.6.87.1-microsoft-standard-WSL2 - Debian trixie ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript See repro above ``` ### Additional context - Possibly related to https://github.com/better-auth/better-auth/issues/949 - This issue does not occur in Better Auth v1.2.7 and starts to occur from v1.2.8-beta.1 onwards - This issue does not occur using either the Admin or the Organization plugins by themselves; the issue only occurs using them together - Tested with Typescript 5.8.3 as well as the 5.9.0-dev.20250617 nightly `tsconfig.json` extract: ```json { "extends": "./node_modules/@tsconfig/bun/tsconfig.json", "compilerOptions": { "incremental": true, "composite": true, "lib": ["ESNext", "DOM", "DOM.Iterable"], "strict": true, "allowUnreachableCode": true, "noPropertyAccessFromIndexSignature": false, "noUnusedLocals": false, "noUnusedParameters": false, "declaration": false, "emitDeclarationOnly": true, "noEmit": false, "isolatedModules": true, "skipLibCheck": true } }
GiteaMirror added the lockedbug labels 2026-04-13 04:55:48 -05:00
Author
Owner

@Rieranthony commented on GitHub (Jun 18, 2025):

I have the same warning, I tried to find a solution but no success yet!

Anytime I try something, I obviously lost the inferred type and lose the reference to org & admin.

<!-- gh-comment-id:2983267695 --> @Rieranthony commented on GitHub (Jun 18, 2025): I have the same warning, I tried to find a solution but no success yet! Anytime I try something, I obviously lost the inferred type and lose the reference to org & admin.
Author
Owner

@ping-maxwell commented on GitHub (Jun 19, 2025):

Hey guys, if possible, remove composite, or set it to false.

<!-- gh-comment-id:2987769115 --> @ping-maxwell commented on GitHub (Jun 19, 2025): Hey guys, if possible, remove `composite`, or set it to `false`.
Author
Owner

@jrizo0 commented on GitHub (Jun 19, 2025):

I was experiencing the same issue. I tried this solution, and it worked:

import { betterAuth, BetterAuthOptions } from "better-auth";

const authConfig = {
  //...
} satisfies BetterAuthOptions;

export const auth = betterAuth(authConfig) as ReturnType<
  typeof betterAuth<typeof authConfig>
>;
<!-- gh-comment-id:2988246817 --> @jrizo0 commented on GitHub (Jun 19, 2025): I was experiencing the same issue. I tried this solution, and it worked: ``` ts import { betterAuth, BetterAuthOptions } from "better-auth"; const authConfig = { //... } satisfies BetterAuthOptions; export const auth = betterAuth(authConfig) as ReturnType< typeof betterAuth<typeof authConfig> >; ```
Author
Owner

@conficiusa commented on GitHub (Jul 10, 2025):

I was experiencing the same issue. I tried this solution, and it worked:

import { betterAuth, BetterAuthOptions } from "better-auth";

const authConfig = {
//...
} satisfies BetterAuthOptions;

export const auth = betterAuth(authConfig) as ReturnType<
typeof betterAuth

;

This fixed it for me

<!-- gh-comment-id:3057372368 --> @conficiusa commented on GitHub (Jul 10, 2025): > I was experiencing the same issue. I tried this solution, and it worked: > > import { betterAuth, BetterAuthOptions } from "better-auth"; > > const authConfig = { > //... > } satisfies BetterAuthOptions; > > export const auth = betterAuth(authConfig) as ReturnType< > typeof betterAuth<typeof authConfig> > >; This fixed it for me
Author
Owner

@benjamin-guibert commented on GitHub (Jul 22, 2025):

I was experiencing the same issue. I tried this solution, and it worked:

import { betterAuth, BetterAuthOptions } from "better-auth";

const authConfig = {
//...
} satisfies BetterAuthOptions;

export const auth = betterAuth(authConfig) as ReturnType<
typeof betterAuth

;

It doesn't work for me, now I have this error on the authConfig:

Exported variable 'authConfig' has or is using name 'OrganizationOptions' from external module "[ROOT]/node_modules/.pnpm/better-auth@1.3.1_react-dom@19.1.0_react@19.1.0/node_modules/better-auth/dist/plugins/organization/index" but cannot be named. ts(4023)
<!-- gh-comment-id:3102872049 --> @benjamin-guibert commented on GitHub (Jul 22, 2025): > I was experiencing the same issue. I tried this solution, and it worked: > > import { betterAuth, BetterAuthOptions } from "better-auth"; > > const authConfig = { > //... > } satisfies BetterAuthOptions; > > export const auth = betterAuth(authConfig) as ReturnType< > typeof betterAuth<typeof authConfig> > >; It doesn't work for me, now I have this error on the `authConfig`: ``` Exported variable 'authConfig' has or is using name 'OrganizationOptions' from external module "[ROOT]/node_modules/.pnpm/better-auth@1.3.1_react-dom@19.1.0_react@19.1.0/node_modules/better-auth/dist/plugins/organization/index" but cannot be named. ts(4023) ```
Author
Owner

@amosbastian commented on GitHub (Aug 12, 2025):

Same problem as @benjamin-guibert. It seemingly keeps coming and going depending on the version and which plugins I use 😭

<!-- gh-comment-id:3180947724 --> @amosbastian commented on GitHub (Aug 12, 2025): Same problem as @benjamin-guibert. It seemingly keeps coming and going depending on the version and which plugins I use 😭
Author
Owner

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

here's what i did instead with oneTimeToken plugin

export const createPublicAuthService = (
  opts: BetterAuthOptions
): ReturnType<typeof betterAuth> => {
  return betterAuth({
    ...opts,
    plugins: [oneTimeToken()],
  })
}

type BaseAuthService = ReturnType<typeof createPublicAuthService>

type AuthApi = BaseAuthService["api"] &
  ReturnType<typeof oneTimeToken>["endpoints"]

export interface PublicAuthService extends BaseAuthService {
  api: AuthApi
}
<!-- gh-comment-id:3193458505 --> @abielzulio commented on GitHub (Aug 16, 2025): here's what i did instead with `oneTimeToken` plugin ```ts export const createPublicAuthService = ( opts: BetterAuthOptions ): ReturnType<typeof betterAuth> => { return betterAuth({ ...opts, plugins: [oneTimeToken()], }) } type BaseAuthService = ReturnType<typeof createPublicAuthService> type AuthApi = BaseAuthService["api"] & ReturnType<typeof oneTimeToken>["endpoints"] export interface PublicAuthService extends BaseAuthService { api: AuthApi } ```
Author
Owner

@RamAvni commented on GitHub (Aug 18, 2025):

What solved it for me was this ReturnType<typeof betterAuth> funny thing:

import { betterAuth } from "better-auth";
import { createPool } from "mysql2/promise";
import { config } from "dotenv";

config({ path: "./.env.development" });

export const auth: ReturnType<typeof betterAuth> = betterAuth({
  database: createPool({
    host: process.env.DB_HOST,
    port: parseInt(process.env.DB_PORT || "3306"),
    user: process.env.DB_USER,
    password: process.env.DB_PASS,
    database: process.env.DB_NAME,
  }),
});
<!-- gh-comment-id:3195052055 --> @RamAvni commented on GitHub (Aug 18, 2025): What solved it for me was this `ReturnType<typeof betterAuth>` funny thing: ```ts import { betterAuth } from "better-auth"; import { createPool } from "mysql2/promise"; import { config } from "dotenv"; config({ path: "./.env.development" }); export const auth: ReturnType<typeof betterAuth> = betterAuth({ database: createPool({ host: process.env.DB_HOST, port: parseInt(process.env.DB_PORT || "3306"), user: process.env.DB_USER, password: process.env.DB_PASS, database: process.env.DB_NAME, }), }); ```
Author
Owner

@j13n commented on GitHub (Sep 3, 2025):

I was experiencing the same issue. I tried this solution, and it worked:

import { betterAuth, BetterAuthOptions } from "better-auth";

const authConfig = {
//...
} satisfies BetterAuthOptions;

export const auth = betterAuth(authConfig) as ReturnType<
typeof betterAuth

;

Just moving my options to a const solved my "The inferred type of this node exceeds the maximum length the compiler will serialize." issue. Didn't have to add the types to the auth object.

<!-- gh-comment-id:3249575181 --> @j13n commented on GitHub (Sep 3, 2025): > I was experiencing the same issue. I tried this solution, and it worked: > > import { betterAuth, BetterAuthOptions } from "better-auth"; > > const authConfig = { > //... > } satisfies BetterAuthOptions; > > export const auth = betterAuth(authConfig) as ReturnType< > typeof betterAuth<typeof authConfig> > >; Just moving my options to a const solved my "The inferred type of this node exceeds the maximum length the compiler will serialize." issue. Didn't have to add the types to the auth object.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9458