The inferred type of 'createAuth' cannot be named without a reference to '.pnpm/@simplewebauthn+server@13.1.1/node_modules/@simplewebauthn/server' #935

Closed
opened 2026-03-13 08:10:31 -05:00 by GiteaMirror · 21 comments
Owner

Originally created by @grmkris on GitHub (Mar 28, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

pnpm monorepo + turborepo
"better-auth": "^1.2.5",

import type { db } from "@/db/db"; // your drizzle instance
import { betterAuth, Auth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import {
  admin,
  anonymous,
  apiKey,
  bearer,
  openAPI,
  organization,
  username,
} from "better-auth/plugins";

import { passkey } from "better-auth/plugins/passkey";
import type { Logger } from "logger";
import { SERVICE_URLS } from "shared";
import { env } from "./env";

export const createAuth = (props: {
  db: db;
  logger?: Logger;
})  => {
  return betterAuth({
    baseURL: SERVICE_URLS[env.APP_ENV].auth,
    basePath: "/api/auth",
    trustedOrigins: [
      SERVICE_URLS[env.APP_ENV].frontend,
      SERVICE_URLS[env.APP_ENV].api,
    ],
    database: drizzleAdapter(props.db, {
      provider: "pg", // or "mysql", "sqlite"
    }),
    plugins: [
      openAPI(),
      anonymous(),
      username(),
      passkey(),
      admin(),
      organization(),
      bearer(),
      apiKey(),
    ],
    emailAndPassword: {
      enabled: true,
    },
    logger: {
      level: env.LOG_LEVEL === "trace" ? "debug" : env.LOG_LEVEL,
      log(level, message, ...args) {
        props.logger?.[level](message, ...args);
      },
    },
    advanced: {
      generateId: false, // ids are generated by drizzle automatically and follow the format defined in shared/id
    },
  });
};

Current vs. Expected behavior

typescript should compile without issues, but here we are getting some infernce issues

What version of Better Auth are you using?

1.2.5

Provide environment information

bun 1.2.6
pnpm 10
pnpm monorepo

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

Types

Auth config (if applicable)

import type { db } from "@/db/db"; // your drizzle instance
import { betterAuth, Auth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import {
  admin,
  anonymous,
  apiKey,
  bearer,
  openAPI,
  organization,
  username,
} from "better-auth/plugins";

import { passkey } from "better-auth/plugins/passkey";
import type { Logger } from "logger";
import { SERVICE_URLS } from "shared";
import { env } from "./env";

export const createAuth = (props: {
  db: db;
  logger?: Logger;
})  => {
  return betterAuth({
    baseURL: SERVICE_URLS[env.APP_ENV].auth,
    basePath: "/api/auth",
    trustedOrigins: [
      SERVICE_URLS[env.APP_ENV].frontend,
      SERVICE_URLS[env.APP_ENV].api,
    ],
    database: drizzleAdapter(props.db, {
      provider: "pg", // or "mysql", "sqlite"
    }),
    plugins: [
      openAPI(),
      anonymous(),
      username(),
      passkey(),
      admin(),
      organization(),
      bearer(),
      apiKey(),
    ],
    emailAndPassword: {
      enabled: true,
    },
    logger: {
      level: env.LOG_LEVEL === "trace" ? "debug" : env.LOG_LEVEL,
      log(level, message, ...args) {
        props.logger?.[level](message, ...args);
      },
    },
    advanced: {
      generateId: false, // ids are generated by drizzle automatically and follow the format defined in shared/id
    },
  });
};

Additional context

No response

Originally created by @grmkris on GitHub (Mar 28, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce pnpm monorepo + turborepo `"better-auth": "^1.2.5",` ``` import type { db } from "@/db/db"; // your drizzle instance import { betterAuth, Auth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { admin, anonymous, apiKey, bearer, openAPI, organization, username, } from "better-auth/plugins"; import { passkey } from "better-auth/plugins/passkey"; import type { Logger } from "logger"; import { SERVICE_URLS } from "shared"; import { env } from "./env"; export const createAuth = (props: { db: db; logger?: Logger; }) => { return betterAuth({ baseURL: SERVICE_URLS[env.APP_ENV].auth, basePath: "/api/auth", trustedOrigins: [ SERVICE_URLS[env.APP_ENV].frontend, SERVICE_URLS[env.APP_ENV].api, ], database: drizzleAdapter(props.db, { provider: "pg", // or "mysql", "sqlite" }), plugins: [ openAPI(), anonymous(), username(), passkey(), admin(), organization(), bearer(), apiKey(), ], emailAndPassword: { enabled: true, }, logger: { level: env.LOG_LEVEL === "trace" ? "debug" : env.LOG_LEVEL, log(level, message, ...args) { props.logger?.[level](message, ...args); }, }, advanced: { generateId: false, // ids are generated by drizzle automatically and follow the format defined in shared/id }, }); }; ``` ### Current vs. Expected behavior typescript should compile without issues, but here we are getting some infernce issues ### What version of Better Auth are you using? 1.2.5 ### Provide environment information ```bash bun 1.2.6 pnpm 10 pnpm monorepo ``` ### Which area(s) are affected? (Select all that apply) Types ### Auth config (if applicable) ```typescript import type { db } from "@/db/db"; // your drizzle instance import { betterAuth, Auth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { admin, anonymous, apiKey, bearer, openAPI, organization, username, } from "better-auth/plugins"; import { passkey } from "better-auth/plugins/passkey"; import type { Logger } from "logger"; import { SERVICE_URLS } from "shared"; import { env } from "./env"; export const createAuth = (props: { db: db; logger?: Logger; }) => { return betterAuth({ baseURL: SERVICE_URLS[env.APP_ENV].auth, basePath: "/api/auth", trustedOrigins: [ SERVICE_URLS[env.APP_ENV].frontend, SERVICE_URLS[env.APP_ENV].api, ], database: drizzleAdapter(props.db, { provider: "pg", // or "mysql", "sqlite" }), plugins: [ openAPI(), anonymous(), username(), passkey(), admin(), organization(), bearer(), apiKey(), ], emailAndPassword: { enabled: true, }, logger: { level: env.LOG_LEVEL === "trace" ? "debug" : env.LOG_LEVEL, log(level, message, ...args) { props.logger?.[level](message, ...args); }, }, advanced: { generateId: false, // ids are generated by drizzle automatically and follow the format defined in shared/id }, }); }; ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:10:31 -05:00
Author
Owner

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

I've been experiencing the same issue while using Bun as the package manager, particularly in a monorepo setup.

When the project is in a standalone (single) repository, everything works as expected and we don't encounter any issues. However, when the same project is placed inside a monorepo, the issue starts to appear.

The type error itself is thrown by BetterAuth, but it may be related to how Bun handles dependency installation in a monorepo. Specifically, Bun installs dependencies globally at the root of the monorepo, rather than within each individual project. As a result,BetterAuth inside the project could have failed to resolve dependencies properly.

This difference in how dependencies are installed might be the root cause of the issue, or at least that’s what I suspect.

@ashfaqnisar commented on GitHub (Mar 28, 2025): I've been experiencing the same issue while using Bun as the package manager, particularly in a monorepo setup. When the project is in a standalone (single) repository, everything works as expected and we don't encounter any issues. However, when the same project is placed inside a monorepo, the issue starts to appear. The type error itself is thrown by BetterAuth, but it may be related to how Bun handles dependency installation in a monorepo. Specifically, Bun installs dependencies globally at the root of the monorepo, rather than within each individual project. As a result,BetterAuth inside the project could have failed to resolve dependencies properly. This difference in how dependencies are installed might be the root cause of the issue, or at least that’s what I suspect.
Author
Owner

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

I've also had this is issue, but with multiple packages where I would get some variation of : "The inferred type of [some variable] cannot be named without a reference to .pnpm/[some package]..."

For me, this only occurs in a project that sets "composite": true in the tsconfig.json.

To solve the error, I install the offending package, that is mentioned in the error, to my devDependencies. However, in this case with the @simplewebauthn/server package, that wasn't enough. I also had to add it to the "types" array field in the tsconfig.json's compilerOptions.

Try adding the @simplewebauthn/server package to your devDependencies and then add "types": ["@simplewebauthn/server"], to the compilerOptions in your tsconfig.

@muytech commented on GitHub (Mar 29, 2025): I've also had this is issue, but with multiple packages where I would get some variation of : "The inferred type of [some variable] cannot be named without a reference to .pnpm/[some package]..." For me, this only occurs in a project that sets "composite": true in the tsconfig.json. To solve the error, I install the offending package, that is mentioned in the error, to my devDependencies. However, in this case with the @simplewebauthn/server package, that wasn't enough. I also had to add it to the "types" array field in the tsconfig.json's compilerOptions. Try adding the @simplewebauthn/server package to your devDependencies and then add `"types": ["@simplewebauthn/server"]`, to the compilerOptions in your tsconfig.
Author
Owner

@matthewlynch commented on GitHub (Apr 1, 2025):

Upgrading to v1.2.5 (from v1.2.4) inside of a pnpm monorepo with turbopack has stared to give me this TS error:
TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.

Downgrading to v1.2.4 seems to have fixed the issue.

Edit: I'm also facing the same TS7056 error outside of a monorepo / not using Turbopack.

@matthewlynch commented on GitHub (Apr 1, 2025): Upgrading to `v1.2.5` (from `v1.2.4`) inside of a pnpm monorepo with turbopack has stared to give me this TS error: `TS7056: The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.` Downgrading to `v1.2.4` seems to have fixed the issue. Edit: I'm also facing the same `TS7056` error outside of a monorepo / not using Turbopack.
Author
Owner

@taylor-lindores-reeves commented on GitHub (Apr 9, 2025):

import { env } from "@/env";
import { createAuthClient } from "better-auth/client";

export const authClient: ReturnType<typeof createAuthClient> = createAuthClient(
  {
    /** the base url of the server (optional if you're using the same domain) */
    baseURL: env.NEXT_PUBLIC_API_URL,
  },
);

@taylor-lindores-reeves commented on GitHub (Apr 9, 2025): ``` import { env } from "@/env"; import { createAuthClient } from "better-auth/client"; export const authClient: ReturnType<typeof createAuthClient> = createAuthClient( { /** the base url of the server (optional if you're using the same domain) */ baseURL: env.NEXT_PUBLIC_API_URL, }, ); ```
Author
Owner

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

import { env } from "@/env";
import { createAuthClient } from "better-auth/client";

export const authClient: ReturnType<typeof createAuthClient> = createAuthClient(
  {
    /** the base url of the server (optional if you're using the same domain) */
    baseURL: env.NEXT_PUBLIC_API_URL,
  },
);

Totally agree!

@PunGrumpy commented on GitHub (Apr 10, 2025): > ``` > import { env } from "@/env"; > import { createAuthClient } from "better-auth/client"; > > export const authClient: ReturnType<typeof createAuthClient> = createAuthClient( > { > /** the base url of the server (optional if you're using the same domain) */ > baseURL: env.NEXT_PUBLIC_API_URL, > }, > ); > ``` Totally agree!
Author
Owner

@pedroota commented on GitHub (Jul 1, 2025):

import { env } from "@/env";
import { createAuthClient } from "better-auth/client";

export const authClient: ReturnType<typeof createAuthClient> = createAuthClient(
  {
    /** the base url of the server (optional if you're using the same domain) */
    baseURL: env.NEXT_PUBLIC_API_URL,
  },
);

If you have plugins, you lose the ability to work with them. For example, I have the organizations plugin, and I can't use it with this solution you provided. But it works well if you don't have any plugins

@pedroota commented on GitHub (Jul 1, 2025): > ``` > import { env } from "@/env"; > import { createAuthClient } from "better-auth/client"; > > export const authClient: ReturnType<typeof createAuthClient> = createAuthClient( > { > /** the base url of the server (optional if you're using the same domain) */ > baseURL: env.NEXT_PUBLIC_API_URL, > }, > ); > ``` If you have plugins, you lose the ability to work with them. For example, I have the organizations plugin, and I can't use it with this solution you provided. But it works well if you don't have any plugins
Author
Owner

@ping-maxwell commented on GitHub (Jul 1, 2025):

It seems that it's been a while since anyone has experienced this issue, I'll close this for now.
If anyone has this issue in the latest version then we can re-open it.

@ping-maxwell commented on GitHub (Jul 1, 2025): It seems that it's been a while since anyone has experienced this issue, I'll close this for now. If anyone has this issue in the latest version then we can re-open it.
Author
Owner

@grmkris commented on GitHub (Jul 1, 2025):

still present :(

@grmkris commented on GitHub (Jul 1, 2025): still present :(
Author
Owner

@Lancer92 commented on GitHub (Jul 3, 2025):

I also experience that issue on 1.2.5. It stop reproducing if I comment out organization() plugin. Switched to 1.2.4 ...

@Lancer92 commented on GitHub (Jul 3, 2025): I also experience that issue on 1.2.5. It stop reproducing if I comment out organization() plugin. Switched to 1.2.4 ...
Author
Owner

@ozgurozalp commented on GitHub (Jul 4, 2025):

same error :(

it's all about organization plugin

@ozgurozalp commented on GitHub (Jul 4, 2025): same error :( it's all about organization plugin
Author
Owner

@armandsalle commented on GitHub (Jul 4, 2025):

Same here... :(

@armandsalle commented on GitHub (Jul 4, 2025): Same here... :(
Author
Owner

@dnyg commented on GitHub (Jul 9, 2025):

Also happening to us. In general it seems to be a quite difficult problem to solve, given that the types of the better-auth plugins are quite inferred depending on the options properties

@dnyg commented on GitHub (Jul 9, 2025): Also happening to us. In general it seems to be a quite difficult problem to solve, given that the types of the better-auth plugins are quite inferred depending on the options properties
Author
Owner

@armandsalle commented on GitHub (Jul 9, 2025):

A fix that works really well for me, thanks to jrizo0

https://github.com/better-auth/better-auth/issues/3067#issuecomment-2988246817

@armandsalle commented on GitHub (Jul 9, 2025): A fix that works really well for me, thanks to [jrizo0](https://github.com/jrizo0) https://github.com/better-auth/better-auth/issues/3067#issuecomment-2988246817
Author
Owner

@Kinfe123 commented on GitHub (Aug 10, 2025):

@grmkris can you please share tsconfig to identify the root cause ?

@Kinfe123 commented on GitHub (Aug 10, 2025): @grmkris can you please share tsconfig to identify the root cause ?
Author
Owner

@drewlyton commented on GitHub (Aug 21, 2025):

This is happening to me in a pnpm monorepo. If I remove the jwt plugin from my plugins array – keeping the organization plugin – it goes away.

Error:

The inferred type of 'auth' cannot be named without a reference to '.pnpm/jose@5.10.0/node_modules/jose'. This is likely not portable. A type annotation is necessary.

tsconfig.json in package

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "baseUrl": ".",
    "rootDir": "src",
    "outDir": "dist"
  },
  "include": ["src/**/*"],
  "exclude": ["dist", "node_modules"]
}

tsconfig.base.json

{
  "compilerOptions": {
    "target": "ES2022",
    "module": "ESNext",
    "moduleResolution": "bundler",
    "strict": true,
    "allowImportingTsExtensions": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "isolatedModules": true,
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "noEmit": true
  }
}

@drewlyton commented on GitHub (Aug 21, 2025): This is happening to me in a pnpm monorepo. If I remove the `jwt` plugin from my plugins array – keeping the `organization` plugin – it goes away. Error: ``` The inferred type of 'auth' cannot be named without a reference to '.pnpm/jose@5.10.0/node_modules/jose'. This is likely not portable. A type annotation is necessary. ``` tsconfig.json in package ``` { "extends": "../../tsconfig.base.json", "compilerOptions": { "baseUrl": ".", "rootDir": "src", "outDir": "dist" }, "include": ["src/**/*"], "exclude": ["dist", "node_modules"] } ``` tsconfig.base.json ``` { "compilerOptions": { "target": "ES2022", "module": "ESNext", "moduleResolution": "bundler", "strict": true, "allowImportingTsExtensions": true, "allowSyntheticDefaultImports": true, "esModuleInterop": true, "skipLibCheck": true, "isolatedModules": true, "declaration": true, "declarationMap": true, "sourceMap": true, "noEmit": true } } ```
Author
Owner

@ntgussoni commented on GitHub (Sep 12, 2025):

Idk if it helps, but im using NX, pnpm.

The error shows only with the magicLinks and apiKeyClient.

I'm on 1.3.9

Image

EDIT:

Image

Seems to make the compiler happy.

@ntgussoni commented on GitHub (Sep 12, 2025): Idk if it helps, but im using NX, pnpm. The error shows only with the magicLinks and apiKeyClient. I'm on 1.3.9 <img width="486" height="466" alt="Image" src="https://github.com/user-attachments/assets/992a2768-5e7e-4b09-9cb6-c2f95c4ffa84" /> EDIT: <img width="343" height="81" alt="Image" src="https://github.com/user-attachments/assets/87d22e3d-4a71-4956-9d4e-2c679f8bf293" /> Seems to make the compiler happy.
Author
Owner

@rjmohammad commented on GitHub (Sep 18, 2025):

The error happens predominantly in monorepos using PNPM.

I resolved it by installing jose and @simplewebauthn/server as dev dependencies (both were causing errors for me).
Then I updated my tsconfig.json with the following:

"types": [
  "node",
  "./node_modules/@simplewebauthn/server/esm/index.d.ts",
  "./node_modules/jose/dist/types/index.d.ts"
]
@rjmohammad commented on GitHub (Sep 18, 2025): The error happens predominantly in monorepos using PNPM. I resolved it by installing `jose` and `@simplewebauthn/server` as dev dependencies (both were causing errors for me). Then I updated my `tsconfig.json` with the following: ```json "types": [ "node", "./node_modules/@simplewebauthn/server/esm/index.d.ts", "./node_modules/jose/dist/types/index.d.ts" ]
Author
Owner

@ping-maxwell commented on GitHub (Oct 5, 2025):

@drewlyton Better-auth often runs into type issues when declaration or declarationMap is enabled in the tsconfig, most cases disabling that resolves it.

Although in recent versions I'm pretty sure (not 100% tho) that we've resolved this issue, so it would be great if you could also ensure you're up to date with Better-Auth.

@ping-maxwell commented on GitHub (Oct 5, 2025): @drewlyton Better-auth often runs into type issues when `declaration` or `declarationMap` is enabled in the tsconfig, most cases disabling that resolves it. Although in recent versions I'm pretty sure (not 100% tho) that we've resolved this issue, so it would be great if you could also ensure you're up to date with Better-Auth.
Author
Owner

@LeulAria commented on GitHub (Oct 19, 2025):

facing same issue here using turbo monorepo

Image
@LeulAria commented on GitHub (Oct 19, 2025): facing same issue here using turbo monorepo <img width="1506" height="186" alt="Image" src="https://github.com/user-attachments/assets/f1422a23-31a4-4db2-815d-9ef21f72f317" />
Author
Owner

@LeulAria commented on GitHub (Oct 19, 2025):

@rjmohammad your solution is working for me too..

@LeulAria commented on GitHub (Oct 19, 2025): @rjmohammad your solution is working for me too..
Author
Owner

@tdnghia98 commented on GitHub (Nov 10, 2025):

It's still happening to me on v1.3.5. If I comment out the jwt extension then the error disappears

@tdnghia98 commented on GitHub (Nov 10, 2025): It's still happening to me on `v1.3.5`. If I comment out the `jwt` extension then the error disappears
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#935