inferred type of '...' cannot be named without a reference

error TS2742: The inferred type of 'plugins' cannot be named without a reference to '...'. This is likely not portable. A type annotation is necessary
4 Replies
Roman
RomanOP4w ago
My config
import {
betterAuth,
type BetterAuthOptions,
type BetterAuthPlugin,
} from "better-auth";

import { prismaAdapter } from "better-auth/adapters/prisma";

import { apiKey, bearer, organization } from "better-auth/plugins";

import { passkey } from "better-auth/plugins/passkey";
import { oneTimeToken } from "better-auth/plugins/one-time-token";

import { prisma } from "@usts/db";

type Prisma = typeof prisma;

type OrganizationPlugin = ReturnType<
typeof organization<Record<string, never>>
>;
type PasskeyPlugin = ReturnType<typeof passkey>;
type ApiKeyPlugin = ReturnType<typeof apiKey>;
type BearerPlugin = ReturnType<typeof bearer>;
type OneTimeTokenPlugin = ReturnType<typeof oneTimeToken>;

const plugins = [
organization() as OrganizationPlugin,
passkey() as PasskeyPlugin,
apiKey() as ApiKeyPlugin,
bearer({ requireSignature: true }) as BearerPlugin,
oneTimeToken({ storeToken: "hashed" }) as OneTimeTokenPlugin,
] as const satisfies BetterAuthPlugin[];

type Plugins = typeof plugins;

const authOptions = {
secret: /* env.BETTER_AUTH_SECRET */ undefined,
baseURL: /* env.BASE_URL */ undefined,

database: prismaAdapter(prisma as Prisma, {
provider: "postgresql",
}),

socialProviders: {
github: {
clientId: /* env.GITHUB_CLIENT_ID */ undefined,
clientSecret: /* env.GITHUB_CLIENT_SECRET */ undefined,
},
} as const,

plugins: plugins as Plugins,
} as const satisfies BetterAuthOptions;

type AuthOptions = typeof authOptions;

type Auth = ReturnType<typeof betterAuth<AuthOptions>>;

export const auth: Auth = betterAuth(authOptions);
import {
betterAuth,
type BetterAuthOptions,
type BetterAuthPlugin,
} from "better-auth";

import { prismaAdapter } from "better-auth/adapters/prisma";

import { apiKey, bearer, organization } from "better-auth/plugins";

import { passkey } from "better-auth/plugins/passkey";
import { oneTimeToken } from "better-auth/plugins/one-time-token";

import { prisma } from "@usts/db";

type Prisma = typeof prisma;

type OrganizationPlugin = ReturnType<
typeof organization<Record<string, never>>
>;
type PasskeyPlugin = ReturnType<typeof passkey>;
type ApiKeyPlugin = ReturnType<typeof apiKey>;
type BearerPlugin = ReturnType<typeof bearer>;
type OneTimeTokenPlugin = ReturnType<typeof oneTimeToken>;

const plugins = [
organization() as OrganizationPlugin,
passkey() as PasskeyPlugin,
apiKey() as ApiKeyPlugin,
bearer({ requireSignature: true }) as BearerPlugin,
oneTimeToken({ storeToken: "hashed" }) as OneTimeTokenPlugin,
] as const satisfies BetterAuthPlugin[];

type Plugins = typeof plugins;

const authOptions = {
secret: /* env.BETTER_AUTH_SECRET */ undefined,
baseURL: /* env.BASE_URL */ undefined,

database: prismaAdapter(prisma as Prisma, {
provider: "postgresql",
}),

socialProviders: {
github: {
clientId: /* env.GITHUB_CLIENT_ID */ undefined,
clientSecret: /* env.GITHUB_CLIENT_SECRET */ undefined,
},
} as const,

plugins: plugins as Plugins,
} as const satisfies BetterAuthOptions;

type AuthOptions = typeof authOptions;

type Auth = ReturnType<typeof betterAuth<AuthOptions>>;

export const auth: Auth = betterAuth(authOptions);
The error
src/index.ts(34,7): error TS2742: The inferred type of 'plugins' cannot be named without a reference to '../node_modules/better-auth/dist/shared/better-auth.kD29xbrE'. This is likely not portable. A type annotation is necessary.
...
src/index.ts(34,7): error TS2742: The inferred type of 'plugins' cannot be named without a reference to '../node_modules/better-auth/dist/shared/better-auth.kD29xbrE'. This is likely not portable. A type annotation is necessary.
...
I've tried doing different things but nothing helps full error
error TS2742: The inferred type of 'plugins' cannot be named without a reference to '../node_modules/better-auth/dist/shared/better-auth.kD29xbrE'. This is likely not portable. A type annotation is necessary.
src/index.ts(34,7): error TS2742: The inferred type of 'plugins' cannot be named without a reference to '.bun/@better-auth+core@1.3.34+291433d3a1a8a313/node_modules/@better-auth/core/db'. This is likely not portable. A type annotation is necessary.
src/index.ts(34,7): error TS2742: The inferred type of 'plugins' cannot be named without a reference to '.bun/@simplewebauthn+server@13.2.2/node_modules/@simplewebauthn/server'. This is likely not portable. A type annotation is necessary.
error TS2742: The inferred type of 'plugins' cannot be named without a reference to '../node_modules/better-auth/dist/shared/better-auth.kD29xbrE'. This is likely not portable. A type annotation is necessary.
src/index.ts(34,7): error TS2742: The inferred type of 'plugins' cannot be named without a reference to '.bun/@better-auth+core@1.3.34+291433d3a1a8a313/node_modules/@better-auth/core/db'. This is likely not portable. A type annotation is necessary.
src/index.ts(34,7): error TS2742: The inferred type of 'plugins' cannot be named without a reference to '.bun/@simplewebauthn+server@13.2.2/node_modules/@simplewebauthn/server'. This is likely not portable. A type annotation is necessary.
Roman
RomanOP4w ago
GitHub
Version 1.3.31 and v1.4.0-beta.13 type inference error requiring re...
Is this suited for github? Yes, this is suited for github To Reproduce Upgrade to version 1.3.31 or v1.4.0-beta.13 and you will see type inference errors like this: The inferred type of this node e...
Maks
Maks4w ago
You need to add this library to the list of direct dependencies if you use pnpm I have the same error with zod and better-call. Added them to my package as deps and it fixed it.
Roman
RomanOP4w ago
better-auth is already a direct dependency

Did you find this page helpful?