[GH-ISSUE #1861] Organizations plugin causes TS2742: The inferred type of 'auth' cannot be named without a reference #26273

Closed
opened 2026-04-17 16:45:46 -05:00 by GiteaMirror · 11 comments
Owner

Originally created by @TheKeveloper on GitHub (Mar 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1861

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Configure tsconfig with:

{
  "compilerOptions":  {
     "declaration": true,
     "declarationMap": true
  }
}

In 1.2.0, I get an error with the following:

export const auth = betterAuth({});

However, in 1.2.1 and beyond, I only get an error if I include the organization plugin:

// The inferred type of 'auth' cannot be named without a reference to '../../node_modules/better-auth/dist/shared/better-auth.3tY5OpnX'. This is likely not portable. A type annotation is necessary.
export const auth = betterAuth({
  plugins: [organization()]
});

Current vs. Expected behavior

I expect to be able to export my auth object while using the organization plugin even if declaration and declarationMap are enabled, as was the case before 1.2.0.

What version of Better Auth are you using?

1.2.1

Provide environment information

- OS: MacOS 15.3.2
- Browser: N/A (this is happening in my server code)
- TypeScript: 5.8.2

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

Types

Auth config (if applicable)

import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins";
export const auth = betterAuth({
  plugins: [organization()]
});

Additional context

This is only an issue if I have declaration: true in my tsconfig, so my temporary workaround is to just disable this for the relevant package.

It would be nice if I didn't have to have that workaround, especially since this only shows up when I include the organization plugin.

Thank you!

Originally created by @TheKeveloper on GitHub (Mar 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1861 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Configure tsconfig with: ```json { "compilerOptions": { "declaration": true, "declarationMap": true } } ``` In `1.2.0`, I get an error with the following: ```typescript export const auth = betterAuth({}); ``` However, in `1.2.1` and beyond, I only get an error if I include the organization plugin: ```typescript // The inferred type of 'auth' cannot be named without a reference to '../../node_modules/better-auth/dist/shared/better-auth.3tY5OpnX'. This is likely not portable. A type annotation is necessary. export const auth = betterAuth({ plugins: [organization()] }); ``` ### Current vs. Expected behavior I expect to be able to export my auth object while using the `organization` plugin even if `declaration` and `declarationMap` are enabled, as was the case before `1.2.0`. ### What version of Better Auth are you using? 1.2.1 ### Provide environment information ```bash - OS: MacOS 15.3.2 - Browser: N/A (this is happening in my server code) - TypeScript: 5.8.2 ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" import { organization } from "better-auth/plugins"; export const auth = betterAuth({ plugins: [organization()] }); ``` ### Additional context This is only an issue if I have `declaration: true` in my tsconfig, so my temporary workaround is to just disable this for the relevant package. It would be nice if I didn't have to have that workaround, especially since this only shows up when I include the organization plugin. Thank you!
GiteaMirror added the lockedbug labels 2026-04-17 16:45:46 -05:00
Author
Owner

@raine-works commented on GitHub (Mar 21, 2025):

I am having the same issue although I am not able to disable declaration in this project because it is being referenced by another project in my repository. I found that typecasting seems to remove the error.

import { betterAuth } from "better-auth"
import { organization } from "better-auth/plugins"
 
export const auth = betterAuth({
    plugins: [ 
        organization() as ReturnType<typeof organization>
    ] 
})
<!-- gh-comment-id:2744678591 --> @raine-works commented on GitHub (Mar 21, 2025): I am having the same issue although I am not able to disable declaration in this project because it is being referenced by another project in my repository. I found that typecasting seems to remove the error. ```ts import { betterAuth } from "better-auth" import { organization } from "better-auth/plugins" export const auth = betterAuth({ plugins: [ organization() as ReturnType<typeof organization> ] }) ```
Author
Owner

@TheKeveloper commented on GitHub (Mar 23, 2025):

The typecasting works if there is no argument to organization. However, if you want to enable teams, for example, then I run into the same issue as above...

<!-- gh-comment-id:2746187165 --> @TheKeveloper commented on GitHub (Mar 23, 2025): The typecasting works if there is no argument to `organization`. However, if you want to enable teams, for example, then I run into the same issue as above...
Author
Owner

@Bekacru commented on GitHub (Mar 27, 2025):

Hey @TheKeveloper can you check if this is still the same in 1.2.5? If so, please share me your tsconfig.

<!-- gh-comment-id:2758055797 --> @Bekacru commented on GitHub (Mar 27, 2025): Hey @TheKeveloper can you check if this is still the same in `1.2.5`? If so, please share me your tsconfig.
Author
Owner

@paulantoine2 commented on GitHub (Mar 27, 2025):

Same issue here. Typecasting works even with teams enabled on 1.2.5 but still does not without Typecasting.

{
  "compilerOptions": {
    "lib": ["esnext"],
    "target": "ESNext",
    "module": "ESNext",
    "moduleDetection": "force",
    "jsx": "react-jsx",
    "jsxImportSource": "hono/jsx",
    "allowJs": true,
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "verbatimModuleSyntax": true,
    "strict": true,
    "skipLibCheck": true,
    "noFallthroughCasesInSwitch": true,
    "noUncheckedIndexedAccess": true,
    "noUnusedLocals": false,
    "noUnusedParameters": false,
    "noPropertyAccessFromIndexSignature": false,
    "outDir": "./dist",
    "declaration": true,
    "declarationMap": true,
    "allowImportingTsExtensions": false,
  }
}
<!-- gh-comment-id:2759727983 --> @paulantoine2 commented on GitHub (Mar 27, 2025): Same issue here. Typecasting works even with teams enabled on 1.2.5 but still does not without Typecasting. ``` { "compilerOptions": { "lib": ["esnext"], "target": "ESNext", "module": "ESNext", "moduleDetection": "force", "jsx": "react-jsx", "jsxImportSource": "hono/jsx", "allowJs": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "verbatimModuleSyntax": true, "strict": true, "skipLibCheck": true, "noFallthroughCasesInSwitch": true, "noUncheckedIndexedAccess": true, "noUnusedLocals": false, "noUnusedParameters": false, "noPropertyAccessFromIndexSignature": false, "outDir": "./dist", "declaration": true, "declarationMap": true, "allowImportingTsExtensions": false, } } ```
Author
Owner

@karimdaghari commented on GitHub (Mar 28, 2025):

Here's what solved it for me:

auth config:

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

const config = {} satisfies BetterAuthOptions 
			   // ^ this is what solves it.

export const auth = betterAuth(config); 

tsconfig.json:

{
	"compilerOptions": {
		"declaration": false,
		"declarationMap": false,
	},
}

<!-- gh-comment-id:2760993157 --> @karimdaghari commented on GitHub (Mar 28, 2025): Here's what solved it for me: **auth config**: ```ts import { betterAuth, type BetterAuthOptions } from "better-auth"; const config = {} satisfies BetterAuthOptions // ^ this is what solves it. export const auth = betterAuth(config); ``` **tsconfig.json**: ```json { "compilerOptions": { "declaration": false, "declarationMap": false, }, } ```
Author
Owner

@valerarusu7 commented on GitHub (Mar 28, 2025):

Here's what solved it for me:

auth config:

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

const config = {} satisfies BetterAuthOptions
// ^ this is what solves it.

export const auth = betterAuth(config);
tsconfig.json:

{
"compilerOptions": {
"declaration": false,
"declarationMap": false,
},
}

This solved it for me as well, thank you.

<!-- gh-comment-id:2762140582 --> @valerarusu7 commented on GitHub (Mar 28, 2025): > Here's what solved it for me: > > **auth config**: > > import { betterAuth, type BetterAuthOptions } from "better-auth"; > > const config = {} satisfies BetterAuthOptions > // ^ this is what solves it. > > export const auth = betterAuth(config); > **tsconfig.json**: > > { > "compilerOptions": { > "declaration": false, > "declarationMap": false, > }, > } This solved it for me as well, thank you.
Author
Owner

@Nedi11 commented on GitHub (Mar 29, 2025):

I am getting
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed

when I add organization plugin

better-auth is on version 1.2.5

<!-- gh-comment-id:2764239189 --> @Nedi11 commented on GitHub (Mar 29, 2025): I am getting ```The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed``` when I add organization plugin better-auth is on version 1.2.5
Author
Owner

@T04435 commented on GitHub (Apr 10, 2025):

Just reverted to 1.2.4 until 1.2.6 is out.

<!-- gh-comment-id:2791648655 --> @T04435 commented on GitHub (Apr 10, 2025): Just reverted to `1.2.4` until `1.2.6` is out.
Author
Owner

@Bekacru commented on GitHub (Apr 12, 2025):

should be fixed from 1.2.6-beta.13

<!-- gh-comment-id:2799039182 --> @Bekacru commented on GitHub (Apr 12, 2025): should be fixed from `1.2.6-beta.13`
Author
Owner

@Bekacru commented on GitHub (Apr 12, 2025):

feel free to re-open and tag me if you're still getting issues

<!-- gh-comment-id:2799039275 --> @Bekacru commented on GitHub (Apr 12, 2025): feel free to re-open and tag me if you're still getting issues
Author
Owner

@john-rtr commented on GitHub (May 27, 2025):

I'm getting this error when using organization plugin + additionnalFields on the user schema.
It works when removing organization plugin or user.additionnalFields, but I need both.

export const getBetterAuthClient = (prismaClient: PrismaService) =>
  betterAuth({
    basePath: '/api/auth',
    database: prismaAdapter(prismaClient, {
      provider: 'postgresql'
    }),
    user: {
      fields: {
        name: 'full_name'
      },
      additionalFields: {
        firstName: {
          type: 'string',
          fieldName: 'first_name'
        },
        lastName: {
          type: 'string',
          fieldName: 'last_name'
        },
        position: {
          type: ['TEST']
        }
      }
    },
    account: {
      modelName: 'UserAuthAccount'
    },
    session: {
      modelName: 'UserSession',
      fields: {}
    },
    verification: {
      modelName: 'UserAuthVerification'
    },
    plugins: [
      organization({
        schema: {
          organization: {
            modelName: 'organisation'
          },
          member: {
            modelName: 'OrganisationTeammate'
          },
          invitation: {
            modelName: 'UserInvitation'
          },
          session: {
            fields: {
              // Organisation field mapping is not working: https://github.com/better-auth/better-auth/issues/1414
              //   activeOrganizationId: 'activeOrganisationId'
            }
          }
        },
        teams: {
          enabled: false
          // Not using teams for now:
          // - User can only be added to 1 team: https://github.com/better-auth/better-auth/issues/1975
          // - Only 1 Member table for Organisation & Team
          // - Missing hooks to implement custom logic with teams & members
        }
      })
    ],
    socialProviders: {
      google: {
        clientId: '' as string,
        clientSecret: '' as string
      }
    }
  } satisfies BetterAuthOptions)
<!-- gh-comment-id:2911827151 --> @john-rtr commented on GitHub (May 27, 2025): I'm getting this error when using organization plugin + additionnalFields on the user schema. It works when removing organization plugin or user.additionnalFields, but I need both. ``` export const getBetterAuthClient = (prismaClient: PrismaService) => betterAuth({ basePath: '/api/auth', database: prismaAdapter(prismaClient, { provider: 'postgresql' }), user: { fields: { name: 'full_name' }, additionalFields: { firstName: { type: 'string', fieldName: 'first_name' }, lastName: { type: 'string', fieldName: 'last_name' }, position: { type: ['TEST'] } } }, account: { modelName: 'UserAuthAccount' }, session: { modelName: 'UserSession', fields: {} }, verification: { modelName: 'UserAuthVerification' }, plugins: [ organization({ schema: { organization: { modelName: 'organisation' }, member: { modelName: 'OrganisationTeammate' }, invitation: { modelName: 'UserInvitation' }, session: { fields: { // Organisation field mapping is not working: https://github.com/better-auth/better-auth/issues/1414 // activeOrganizationId: 'activeOrganisationId' } } }, teams: { enabled: false // Not using teams for now: // - User can only be added to 1 team: https://github.com/better-auth/better-auth/issues/1975 // - Only 1 Member table for Organisation & Team // - Missing hooks to implement custom logic with teams & members } }) ], socialProviders: { google: { clientId: '' as string, clientSecret: '' as string } } } satisfies BetterAuthOptions) ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#26273