[GH-ISSUE #8623] TS2742: the inferred type cannot be named without a reference to node_modules/better-auth/dist/client/path-to-object.d.mts (v1.5.5) #11143

Open
opened 2026-04-13 07:30:31 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @nktnet1 on GitHub (Mar 15, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/8623

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Clone https://github.com/nktnet1/rt-stack
  2. Run git checkout 6d13663 (commit 6d13663 is the last commit before the workaround was applied)
  3. Run pnpm install && pnpm --filter=web typecheck and confirm that there are no issues
  4. Update the version of better-auth in pnpm-workspace.yaml from 1.5.4 to 1.5.5
  5. Run pnpm clean && pnpm install && pnpm --filter=web typecheck
  6. Observe the error

Current vs. Expected behavior

There should be no type errors when building.

Instead, I get the following error:

src/clients/authClient.ts:4:14 - error TS2742: The inferred type of 'authClient' cannot be named without a reference
 to '../../../../packages/auth/node_modules/better-auth/dist/client/path-to-object.d.mts'. This is likely not portab
le. A type annotation is necessary.

4 export const authClient = createAuthClient({

What version of Better Auth are you using?

1.5.5

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 24.6.0: Wed Nov  5 21:32:34 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6020",
    "release": "24.6.0",
    "cpuCount": 12,
    "cpuModel": "Apple M2 Max",
    "totalMemory": "32.00 GB",
    "freeMemory": "1.67 GB"
  },
  "node": {
    "version": "v24.9.0",
    "env": "development"
  },
  "packageManager": {
    "name": "pnpm",
    "version": "10.32.1"
  },
  "frameworks": null,
  "databases": null,
  "betterAuth": {
    "version": "Unknown",
    "config": null
  }
}

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

Types

Auth config (if applicable)

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

import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { openAPI } from 'better-auth/plugins';
import urlJoin from 'url-join';
import type { DatabaseInstance } from '@repo/db/client';

export interface AuthOptions {
  webUrl: string;
  serverUrl: string;
  apiPath: `/${string}`;
  authSecret: string;
  db: DatabaseInstance;
}

export type AuthInstance = ReturnType<typeof createAuth>;

/**
 * This function is abstracted for schema generations in cli-config.ts
 */
export const getBaseOptions = (db: DatabaseInstance) =>
  ({
    database: drizzleAdapter(db, {
      provider: 'pg',
    }),

    /**
     * Only uncomment the line below if you are using plugins, so that
     * your types can be correctly inferred:
     */
    plugins: [openAPI()],
  }) satisfies BetterAuthOptions;

export const createAuth = ({
  webUrl,
  serverUrl,
  apiPath,
  db,
  authSecret,
}: AuthOptions) => {
  return betterAuth({
    ...getBaseOptions(db),
    baseURL: urlJoin(serverUrl, apiPath, 'auth'),
    secret: authSecret,
    trustedOrigins: [webUrl].map((url) => new URL(url).origin),
    session: {
      cookieCache: {
        enabled: true,
        maxAge: 5 * 60,
      },
    },
    emailAndPassword: {
      enabled: true,
      autoSignIn: true,
      requireEmailVerification: false,
    },
  });
};

Additional context

The last working version is 1.5.4 - the issue was introduced in 1.5.5.

Originally created by @nktnet1 on GitHub (Mar 15, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/8623 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Clone https://github.com/nktnet1/rt-stack 2. Run `git checkout 6d13663` (commit [6d13663](https://github.com/nktnet1/rt-stack/commit/6d13663) is the last commit before the workaround was applied) 2. Run `pnpm install && pnpm --filter=web typecheck` and confirm that there are no issues 3. Update the version of `better-auth` in `pnpm-workspace.yaml` from `1.5.4` to `1.5.5` 4. Run `pnpm clean && pnpm install && pnpm --filter=web typecheck` 5. Observe the error ### Current vs. Expected behavior There should be no type errors when building. Instead, I get the following error: ``` src/clients/authClient.ts:4:14 - error TS2742: The inferred type of 'authClient' cannot be named without a reference to '../../../../packages/auth/node_modules/better-auth/dist/client/path-to-object.d.mts'. This is likely not portab le. A type annotation is necessary. 4 export const authClient = createAuthClient({ ``` ### What version of Better Auth are you using? 1.5.5 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 24.6.0: Wed Nov 5 21:32:34 PST 2025; root:xnu-11417.140.69.705.2~1/RELEASE_ARM64_T6020", "release": "24.6.0", "cpuCount": 12, "cpuModel": "Apple M2 Max", "totalMemory": "32.00 GB", "freeMemory": "1.67 GB" }, "node": { "version": "v24.9.0", "env": "development" }, "packageManager": { "name": "pnpm", "version": "10.32.1" }, "frameworks": null, "databases": null, "betterAuth": { "version": "Unknown", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript import { type BetterAuthOptions, betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { openAPI } from 'better-auth/plugins'; import urlJoin from 'url-join'; import type { DatabaseInstance } from '@repo/db/client'; export interface AuthOptions { webUrl: string; serverUrl: string; apiPath: `/${string}`; authSecret: string; db: DatabaseInstance; } export type AuthInstance = ReturnType<typeof createAuth>; /** * This function is abstracted for schema generations in cli-config.ts */ export const getBaseOptions = (db: DatabaseInstance) => ({ database: drizzleAdapter(db, { provider: 'pg', }), /** * Only uncomment the line below if you are using plugins, so that * your types can be correctly inferred: */ plugins: [openAPI()], }) satisfies BetterAuthOptions; export const createAuth = ({ webUrl, serverUrl, apiPath, db, authSecret, }: AuthOptions) => { return betterAuth({ ...getBaseOptions(db), baseURL: urlJoin(serverUrl, apiPath, 'auth'), secret: authSecret, trustedOrigins: [webUrl].map((url) => new URL(url).origin), session: { cookieCache: { enabled: true, maxAge: 5 * 60, }, }, emailAndPassword: { enabled: true, autoSignIn: true, requireEmailVerification: false, }, }); }; ``` ### Additional context The last working version is 1.5.4 - the issue was introduced in 1.5.5.
GiteaMirror added the corebug labels 2026-04-13 07:30:31 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 15, 2026):

This is a known type portability issue that has affected other users, particularly in monorepo setups with pnpm. Version 1.5.5 included type export changes to path-to-object that likely triggered this in your setup.

Recommended workaround — add an explicit type annotation:

export const authClient = createAuthClient({...}) as ReturnType<typeof createAuthClient>;

This forces TypeScript to use the return type instead of inferring the internal types that cross package boundaries.

Alternative approaches:

  • Run pnpm dedupe to ensure all better-auth packages resolve to single versions
  • Set "declaration": false in your tsconfig if you don't need to export types from your auth package
  • Try "moduleResolution": "bundler" if you're not already using it

This is a systemic issue caused by internal types not being exported at the top level, and pnpm's strict dependency resolution makes it more visible than other package managers.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:4064187625 --> @dosubot[bot] commented on GitHub (Mar 15, 2026): <!-- Answer --> This is a known type portability issue that has affected other users, particularly in monorepo setups with pnpm. Version 1.5.5 included [type export changes to path-to-object](https://github.com/better-auth/better-auth/pull/8497) that likely triggered this in your setup. **Recommended workaround** — add an explicit type annotation: ```typescript export const authClient = createAuthClient({...}) as ReturnType<typeof createAuthClient>; ``` This forces TypeScript to use the return type instead of inferring the internal types that cross package boundaries. **Alternative approaches:** - Run `pnpm dedupe` to ensure all better-auth packages resolve to single versions - Set `"declaration": false` in your tsconfig if you don't need to export types from your auth package - Try `"moduleResolution": "bundler"` if you're not already using it This is a [systemic issue](https://github.com/better-auth/better-auth/issues/5666) caused by internal types not being exported at the top level, and pnpm's strict dependency resolution makes it more visible than other package managers. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/568eb349-7126-483d-a60e-55eb59c016fb?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20type%20portability%20issue%20that%20has%20affected%20other%20users%2C%20particularly%20in%20monorepo%20setups%20with%20pnpm.%20Version%201.5.5%20included%20%5Btype%20export%20changes%20to%20path-to-object%5D%28https%3A//github.com/better-auth/better-auth/pull/8497%29%20that%20likely%20triggered%20this%20in%20your%20setup.%0A%0A%2A%2ARecommended%20workaround%2A%2A%20%E2%80%94%20add%20an%20explicit%20type%20annotation%3A%0A%0A%60%60%60typescript%0Aexport%20const%20authClient%20%3D%20createAuthClient%28%7B...%7D%29%20as%20ReturnType%3Ctypeof%20createAuthClient%3E%3B%0A%60%60%60%0A%0AThis%20forces%20TypeScript%20to%20use%20the%20return%20type%20instead%20of%20inferring%20the%20internal%20types%20that%20cross%20package%20boundaries.%0A%0A%2A%2AAlternative%20approaches%3A%2A%2A%0A-%20Run%20%60pnpm%20dedupe%60%20to%20ensure%20all%20better-auth%20packages%20resolve%20to%20single%20versions%0A-%20Set%20%60%22declaration%22%3A%20false%60%20in%20your%20tsconfig%20if%20you%20don%27t%20need%20to%20export%20types%20from%20your%20auth%20package%0A-%20Try%20%60%22moduleResolution%22%3A%20%22bundler%22%60%20if%20you%27re%20not%20already%20using%20it%0A%0AThis%20is%20a%20%5Bsystemic%20issue%5D%28https%3A//github.com/better-auth/better-auth/issues/5666%29%20caused%20by%20internal%20types%20not%20being%20exported%20at%20the%20top%20level%2C%20and%20pnpm%27s%20strict%20dependency%20resolution%20makes%20it%20more%20visible%20than%20other%20package%20managers.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8623)
Author
Owner

@nktnet1 commented on GitHub (Mar 22, 2026):

The workaround

ReturnType<typeof createAuthClient>

does work. However, I'll leave this issue open since it's a breaking change between 1.5.4 to 1.5.5 (also tested in 1.5.6).

<!-- gh-comment-id:4107058224 --> @nktnet1 commented on GitHub (Mar 22, 2026): The workaround ```ts ReturnType<typeof createAuthClient> ``` does work. However, I'll leave this issue open since it's a breaking change between 1.5.4 to 1.5.5 (also tested in 1.5.6).
Author
Owner

@aurelientanguy commented on GitHub (Mar 24, 2026):

My auth client setup:

import { createAuthClient as createBetterAuthClient } from "better-auth/react";
import type { BetterAuthClientOptions } from "better-auth";
import { stripeClient } from "@better-auth/stripe/client";
import {
  adminClient,
  customSessionClient,
  inferAdditionalFields,
  inferOrgAdditionalFields,
  lastLoginMethodClient,
  magicLinkClient,
  organizationClient,
  twoFactorClient,
} from "better-auth/client/plugins";

import type { Auth } from "./server";
import {
  ac,
  owner,
  admin,
  member,
  accountant,
} from "./plugins/organizations/roles";

type AuthClientOptions = {
  baseURL: string;
  basePath?: string;
};

const createAuthClient = ({
  baseURL,
  basePath = "/api/auth",
}: AuthClientOptions) =>
  createBetterAuthClient({
    baseURL,
    basePath,

    plugins: [
      inferAdditionalFields<Auth>(),
      customSessionClient<Auth>(),
      adminClient({
        ac,
        roles: { owner, admin, member, accountant },
      }),
      twoFactorClient(),
      lastLoginMethodClient(),
      magicLinkClient(),
      stripeClient({ subscription: true }),
      organizationClient({
        ac,
        roles: { owner, admin, member, accountant },
        schema: inferOrgAdditionalFields<Auth>(),
      }),
    ],
  } satisfies BetterAuthClientOptions);

type AuthClient = ReturnType<typeof createAuthClient>;

export { createAuthClient };
export type { AuthClient };

had similar TS errors :

The inferred type of 'createAuthClient' cannot be named without a reference to '../node_modules/better-auth/dist/client/path-to-object.mjs'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'createAuthClient' cannot be named without a reference to '../node_modules/better-auth/dist/client/query.mjs'. This is likely not portable. A type annotation is necessary.ts(2742)
The inferred type of 'createAuthClient' cannot be named without a reference to '../node_modules/better-auth/dist/db/field.mjs'. This is likely not portable. A type annotation is necessary.ts(2742)

so I found this temporary fix:

/**
 * Re-exports symbols that appear in the inferred type of `createAuthClient` so declaration emit
 * (TS2883 / “cannot be named without a reference …”) can serialize `.d.ts` output for this package.
 *
 * **Temporary:** remove when better-auth’s published types no longer force consumers to anchor these
 * names (see issues below).
 *
 * @see https://github.com/better-auth/better-auth/issues/4250
 * @see https://github.com/better-auth/better-auth/issues/8623
 */
export type {
  AuthQueryAtom,
  InferSignUpEmailCtx,
  InferUserUpdateCtx,
} from "better-auth/client";
export type { FieldAttributeToObject } from "better-auth/db";

It does the job.
I'm using tsgo in a monorepo with references enabled and type declarations in each package.

<!-- gh-comment-id:4117591146 --> @aurelientanguy commented on GitHub (Mar 24, 2026): My auth client setup: ```ts import { createAuthClient as createBetterAuthClient } from "better-auth/react"; import type { BetterAuthClientOptions } from "better-auth"; import { stripeClient } from "@better-auth/stripe/client"; import { adminClient, customSessionClient, inferAdditionalFields, inferOrgAdditionalFields, lastLoginMethodClient, magicLinkClient, organizationClient, twoFactorClient, } from "better-auth/client/plugins"; import type { Auth } from "./server"; import { ac, owner, admin, member, accountant, } from "./plugins/organizations/roles"; type AuthClientOptions = { baseURL: string; basePath?: string; }; const createAuthClient = ({ baseURL, basePath = "/api/auth", }: AuthClientOptions) => createBetterAuthClient({ baseURL, basePath, plugins: [ inferAdditionalFields<Auth>(), customSessionClient<Auth>(), adminClient({ ac, roles: { owner, admin, member, accountant }, }), twoFactorClient(), lastLoginMethodClient(), magicLinkClient(), stripeClient({ subscription: true }), organizationClient({ ac, roles: { owner, admin, member, accountant }, schema: inferOrgAdditionalFields<Auth>(), }), ], } satisfies BetterAuthClientOptions); type AuthClient = ReturnType<typeof createAuthClient>; export { createAuthClient }; export type { AuthClient }; ``` had similar TS errors : ``` The inferred type of 'createAuthClient' cannot be named without a reference to '../node_modules/better-auth/dist/client/path-to-object.mjs'. This is likely not portable. A type annotation is necessary.ts(2742) ``` ``` The inferred type of 'createAuthClient' cannot be named without a reference to '../node_modules/better-auth/dist/client/query.mjs'. This is likely not portable. A type annotation is necessary.ts(2742) ``` ``` The inferred type of 'createAuthClient' cannot be named without a reference to '../node_modules/better-auth/dist/db/field.mjs'. This is likely not portable. A type annotation is necessary.ts(2742) ``` so I found this temporary fix: ```ts /** * Re-exports symbols that appear in the inferred type of `createAuthClient` so declaration emit * (TS2883 / “cannot be named without a reference …”) can serialize `.d.ts` output for this package. * * **Temporary:** remove when better-auth’s published types no longer force consumers to anchor these * names (see issues below). * * @see https://github.com/better-auth/better-auth/issues/4250 * @see https://github.com/better-auth/better-auth/issues/8623 */ export type { AuthQueryAtom, InferSignUpEmailCtx, InferUserUpdateCtx, } from "better-auth/client"; export type { FieldAttributeToObject } from "better-auth/db"; ``` It does the job. I'm using `tsgo` in a monorepo with references enabled and type declarations in each package.
Author
Owner

@mohitkumawat310 commented on GitHub (Apr 12, 2026):

I know this is not what you want, but

Downgrading to version better-auth@1.4.17 fixed this problem.

Update:

1.5.5 works too

<!-- gh-comment-id:4232083578 --> @mohitkumawat310 commented on GitHub (Apr 12, 2026): I know this is not what you want, but Downgrading to version better-auth@1.4.17 fixed this problem. Update: 1.5.5 works too
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#11143