[GH-ISSUE #6909] NestJS and Expo The inferred type of 'auth' cannot be named without a reference #19299

Closed
opened 2026-04-15 18:12:21 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @edw19 on GitHub (Dec 20, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6909

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

The inferred type of 'auth' cannot be named without a reference to '.pnpm/better-call@1.1.5_zod@4.1.13/node_modules/better-call'. This is likely not portable. A type annotation is necessary.ts(2742)

When add the expo plugin ts give me this error, i try disabled error with ts config

"declaration": false,
and the error disappears

but when send my app to deploy i have to next error

ode:internal/modules/cjs/loader:1309
throw new ERR_REQUIRE_ESM(filename, true);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7_@better-auth+core@1.4.7_@better-auth+utils@0.3.0_@better-fetch+fetch@ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs not supported.
Instead change the require of /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7https://github.com/better-auth+core@1.4.7_@better-auth+utils@0.3.0_@better-fetch+fetch@ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
 ELIFECYCLE  Command failed with exit code 1.
node:internal/modules/cjs/loader:1309
throw new ERR_REQUIRE_ESM(filename, true);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7https://github.com/better-auth+core@1.4.7_@better-auth+utils@0.3.0_@better-fetch+fetch@ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs not supported.
Instead change the require of /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7https://github.com/better-auth+core@1.4.7_@better-auth+utils@0.3.0_@better-fetch+fetch@_ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object. (/app/dist/auth.js:7:16) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v22.11.0

better auto expo has support for nest js modules ?

the error only appears when i add the pluggin 😪

Image

Current vs. Expected behavior

should be works with plugin and nestjs and expo plugin

What version of Better Auth are you using?

1.3.8

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 10 Pro",
    "release": "10.0.19045",
    "cpuCount": 16,
    "cpuModel": "AMD Ryzen 7 5700X 8-Core Processor
",
    "totalMemory": "31.91 GB",
    "freeMemory": "20.93 GB"
  },
  "node": {
    "version": "v24.6.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "11.5.1"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "@prisma/client",
      "version": "6.7.0"
    }
  ],
  "betterAuth": {
    "version": "1.3.8",
    "config": {
      "plugins": [],
      "emailAndPassword": {
        "enabled": true
      },
      "baseURL": "https://ab5047639dd0.ngrok-free.app",
      "basePath": "/api/auth",
      "socialProviders": {
        "google": {
          "clientId": "[REDACTED]",
          "clientSecret": "[REDACTED]"
        }
      },
      "trustedOrigins": [
        "http://localhost:3000",
        "https://ui-test.lessa.app",
        "https://www.lessa.app",
        "https://juntas-agua-potable.vercel.app",
        "https://junta-de-agua.lessa.app",
        "lessaapp://",
        "exp://*/*",
        "exp://10.0.0.*:*/*",
        "exp://192.168.*.*:*/*",
        "exp://172.*.*.*:*/*",
        "exp://localhost:*/*",
        "exp://192.168.11.36:8081",
        "exp://192.168.11.36:8081/*"
      ],
      "advanced": {
        "crossSubDomainCookies": {
          "enabled": true
        }
      },
      "allowMissingOrigin": true
    }
  }
}

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

Backend

Auth config (if applicable)

import { prismaAdapter } from "better-auth/adapters/prisma";
import { PrismaClient } from "@prisma/client";
import { betterAuth } from "better-auth";
import { expo } from "@better-auth/expo";

const prisma = new PrismaClient();

export const auth = betterAuth({
    plugins: [
        expo()
    ],
    emailAndPassword: {
        enabled: true
    },
    // advanced: {
    //     disableOriginCheck: true
    // },
    baseURL: process.env.BETTER_AUTH_URL,
    basePath: "/api/auth",
    socialProviders: {
        google: {
            clientId: process.env.GOOGLE_CLIENT_ID as string,
            clientSecret: process.env.GOOGLE_CLIENT_SECRET as string
        }
    },
    database: prismaAdapter(prisma, {
        provider: "postgresql"
    }),
    trustedOrigins: [
        'http://localhost:3000',
        "https://ui-test.lessa.app",
        "https://www.lessa.app",
        "https://juntas-agua-potable.vercel.app",
        "https://junta-de-agua.lessa.app",
        // movile,
        "lessaapp://",
        // ...(process.env.NODE_ENV === "development" ? [
        "exp://*/*",                 // Trust all Expo development URLs
        "exp://10.0.0.*:*/*",        // Trust 10.0.0.x IP range
        "exp://192.168.*.*:*/*",     // Trust 192.168.x.x IP range
        "exp://172.*.*.*:*/*",       // Trust 172.x.x.x IP range
        "exp://localhost:*/*",       // Trust localhost
        "exp://192.168.11.36:8081",      // Sin path - permite cualquier ruta
        "exp://192.168.11.36:8081/*"
        // ] : [])
    ],
    advanced: {
        crossSubDomainCookies: {
            enabled: true
        },
        ...(process.env.NODE_ENV === "production" ? {
            defaultCookieAttributes: {
                secure: true,
                sameSite: "none",
                domain: ".lessa.app"  //  con punto al inicio para subdominios
            }
        } : {}),
    },
    allowMissingOrigin: true,
})

Additional context

No response

Originally created by @edw19 on GitHub (Dec 20, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6909 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce The inferred type of 'auth' cannot be named without a reference to '.pnpm/better-call@1.1.5_zod@4.1.13/node_modules/better-call'. This is likely not portable. A type annotation is necessary.ts(2742) When add the expo plugin ts give me this error, i try disabled error with ts config "declaration": false, and the error disappears but when send my app to deploy i have to next error ode:internal/modules/cjs/loader:1309 throw new ERR_REQUIRE_ESM(filename, true); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/.pnpm/https://github.com/better-auth+expo@[1.4.7_@better-auth](mailto:1.4.7_@better-auth)+core@[1.4.7_@better-auth](mailto:1.4.7_@better-auth)+utils@[0.3.0_@better-fetch](mailto:0.3.0_@better-fetch)+fetch@ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs not supported. Instead change the require of /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7https://github.com/better-auth+core@[1.4.7_@better-auth](mailto:1.4.7_@better-auth)+utils@[0.3.0_@better-fetch](mailto:0.3.0_@better-fetch)+fetch@ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs to a dynamic import() which is available in all CommonJS modules. at TracingChannel.traceSync (node:diagnostics_channel:315:14)  ELIFECYCLE  Command failed with exit code 1. node:internal/modules/cjs/loader:1309 throw new ERR_REQUIRE_ESM(filename, true); ^ Error [ERR_REQUIRE_ESM]: require() of ES Module /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7https://github.com/better-auth+core@[1.4.7_@better-auth](mailto:1.4.7_@better-auth)+utils@[0.3.0_@better-fetch](mailto:0.3.0_@better-fetch)+fetch@ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs not supported. Instead change the require of /app/node_modules/.pnpm/https://github.com/better-auth+expo@1.4.7https://github.com/better-auth+core@[1.4.7_@better-auth](mailto:1.4.7_@better-auth)+utils@[0.3.0_@better-fetch](mailto:0.3.0_@better-fetch)+fetch@_ez3g47vwejg7obxg356w363qze/node_modules/@better-auth/expo/dist/index.mjs to a dynamic import() which is available in all CommonJS modules. at TracingChannel.traceSync (node:diagnostics_channel:315:14) at Object. (/app/dist/auth.js:7:16) { code: 'ERR_REQUIRE_ESM' } Node.js v22.11.0 better auto expo has support for nest js modules ? the error only appears when i add the pluggin 😪 <img width="963" height="163" alt="Image" src="https://github.com/user-attachments/assets/19896843-97e1-4c79-89a1-24f8f13b14d6" /> ### Current vs. Expected behavior should be works with plugin and nestjs and expo plugin ### What version of Better Auth are you using? 1.3.8 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 10 Pro", "release": "10.0.19045", "cpuCount": 16, "cpuModel": "AMD Ryzen 7 5700X 8-Core Processor ", "totalMemory": "31.91 GB", "freeMemory": "20.93 GB" }, "node": { "version": "v24.6.0", "env": "development" }, "packageManager": { "name": "npm", "version": "11.5.1" }, "frameworks": null, "databases": [ { "name": "@prisma/client", "version": "6.7.0" } ], "betterAuth": { "version": "1.3.8", "config": { "plugins": [], "emailAndPassword": { "enabled": true }, "baseURL": "https://ab5047639dd0.ngrok-free.app", "basePath": "/api/auth", "socialProviders": { "google": { "clientId": "[REDACTED]", "clientSecret": "[REDACTED]" } }, "trustedOrigins": [ "http://localhost:3000", "https://ui-test.lessa.app", "https://www.lessa.app", "https://juntas-agua-potable.vercel.app", "https://junta-de-agua.lessa.app", "lessaapp://", "exp://*/*", "exp://10.0.0.*:*/*", "exp://192.168.*.*:*/*", "exp://172.*.*.*:*/*", "exp://localhost:*/*", "exp://192.168.11.36:8081", "exp://192.168.11.36:8081/*" ], "advanced": { "crossSubDomainCookies": { "enabled": true } }, "allowMissingOrigin": true } } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { prismaAdapter } from "better-auth/adapters/prisma"; import { PrismaClient } from "@prisma/client"; import { betterAuth } from "better-auth"; import { expo } from "@better-auth/expo"; const prisma = new PrismaClient(); export const auth = betterAuth({ plugins: [ expo() ], emailAndPassword: { enabled: true }, // advanced: { // disableOriginCheck: true // }, baseURL: process.env.BETTER_AUTH_URL, basePath: "/api/auth", socialProviders: { google: { clientId: process.env.GOOGLE_CLIENT_ID as string, clientSecret: process.env.GOOGLE_CLIENT_SECRET as string } }, database: prismaAdapter(prisma, { provider: "postgresql" }), trustedOrigins: [ 'http://localhost:3000', "https://ui-test.lessa.app", "https://www.lessa.app", "https://juntas-agua-potable.vercel.app", "https://junta-de-agua.lessa.app", // movile, "lessaapp://", // ...(process.env.NODE_ENV === "development" ? [ "exp://*/*", // Trust all Expo development URLs "exp://10.0.0.*:*/*", // Trust 10.0.0.x IP range "exp://192.168.*.*:*/*", // Trust 192.168.x.x IP range "exp://172.*.*.*:*/*", // Trust 172.x.x.x IP range "exp://localhost:*/*", // Trust localhost "exp://192.168.11.36:8081", // Sin path - permite cualquier ruta "exp://192.168.11.36:8081/*" // ] : []) ], advanced: { crossSubDomainCookies: { enabled: true }, ...(process.env.NODE_ENV === "production" ? { defaultCookieAttributes: { secure: true, sameSite: "none", domain: ".lessa.app" // con punto al inicio para subdominios } } : {}), }, allowMissingOrigin: true, }) ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-15 18:12:21 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 20, 2025):

The error you're encountering, "The inferred type of 'auth' cannot be named without a reference," typically arises from TypeScript's inability to properly infer types across different modules or due to incompatible modules being used. It seems to be affecting NestJS integration with Better Auth, particularly with the Expo plugin.

Here are some troubleshooting steps you can take:

  1. Update Packages: Ensure that you are using the latest versions of Better Auth and its dependencies. Check if updated versions resolve this issue. Specifically, you mentioned using Better Auth version 1.3.8; consider updating to the latest version if available.

  2. Type Annotation: As suggested in an open GitHub issue, adding explicit type annotations can help alleviate TypeScript's inference issues. Try explicitly defining the type of the auth object when you are creating it.

  3. Plugin Configuration: Make sure the Expo plugin is properly integrated. The plugin might not be compatible with the current NestJS or TypeScript configuration, leading to these type inference issues. Check the plugin documentation for any compatibility notes or required configurations.

  4. Disable Type Checking: Although disabling TypeScript errors is not advisable for production, it may help narrow down the issue. You mentioned that setting "declaration": false in your tsconfig.json alleviates the immediate error, but you should address the root cause to avoid deployment issues.

  5. Dynamic Import: If you receive an error about requiring an ES Module, consider switching to dynamic imports (import()) instead of static requires for the module that is throwing the error. This change may resolve compatibility issues between CommonJS and ES Modules.

If these steps do not resolve the issue, I recommend reaching out to the Better Auth team on GitHub by tagging @bekacru or @ping__, as they may have more specific insights into compatibility issues between Better Auth, NestJS, and Expo.

What other errors or issues have you encountered while trying these solutions?

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3677896950 --> @better-auth-agent[bot] commented on GitHub (Dec 20, 2025): The error you're encountering, "The inferred type of 'auth' cannot be named without a reference," typically arises from TypeScript's inability to properly infer types across different modules or due to incompatible modules being used. It seems to be affecting NestJS integration with Better Auth, particularly with the Expo plugin. Here are some troubleshooting steps you can take: 1. **Update Packages**: Ensure that you are using the latest versions of Better Auth and its dependencies. Check if updated versions resolve this issue. Specifically, you mentioned using Better Auth version 1.3.8; consider updating to the latest version if available. 2. **Type Annotation**: As suggested in an open GitHub issue, adding explicit type annotations can help alleviate TypeScript's inference issues. Try explicitly defining the type of the `auth` object when you are creating it. 3. **Plugin Configuration**: Make sure the Expo plugin is properly integrated. The plugin might not be compatible with the current NestJS or TypeScript configuration, leading to these type inference issues. Check the plugin documentation for any compatibility notes or required configurations. 4. **Disable Type Checking**: Although disabling TypeScript errors is not advisable for production, it may help narrow down the issue. You mentioned that setting `"declaration": false` in your `tsconfig.json` alleviates the immediate error, but you should address the root cause to avoid deployment issues. 5. **Dynamic Import**: If you receive an error about requiring an ES Module, consider switching to dynamic imports (`import()`) instead of static requires for the module that is throwing the error. This change may resolve compatibility issues between CommonJS and ES Modules. If these steps do not resolve the issue, I recommend reaching out to the Better Auth team on GitHub by tagging @bekacru or @ping__, as they may have more specific insights into compatibility issues between Better Auth, NestJS, and Expo. What other errors or issues have you encountered while trying these solutions? _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 20, 2025):

Hi @edw19! I'm Dosu and I’m helping the better-auth team.

Your TypeScript error (TS2742) happens because the inferred type of auth references internal types from dependencies like better-call, which aren't exported at the top level—this is a known issue when using plugins like Expo in Better Auth, especially with pnpm or monorepos. The most reliable workaround is to use an explicit type annotation when exporting auth, for example:

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

or, if you want to keep plugin inference, you can cast the plugin as any or BetterAuthPlugin:

plugins: [expo() as any]

or

plugins: [expo() as unknown as BetterAuthPlugin]

This will suppress the error, but you may lose some type safety for the plugin itself. Disabling "declaration" in your tsconfig.json hides the error because TypeScript stops emitting declaration files, but this can impact type safety and portability, and doesn't fix the root cause (source).

The Node.js ERR_REQUIRE_ESM error is because @better-auth/expo is published as an ES module only ("type": "module", main entry is .mjs), so it can't be loaded with require() in a CommonJS (CJS) context, which is the default for many NestJS projects. To resolve this, you need to either:

  • Migrate your backend to ESM (set "type": "module" in your package.json, use import instead of require, and ensure all dependencies support ESM).
  • Use dynamic import() for the Expo plugin in your code if you must stay on CJS (though this can be tricky with NestJS module loading).
  • There is no CJS build of the Expo plugin, so aliasing to a CJS version is not possible.

The Expo plugin is designed to be used on the server side (including with NestJS) if your backend supports ESM and you add the plugin to your Better Auth config. There is no special NestJS integration, but it works as long as your server can import ESM modules (source, source).

If you can't migrate your backend to ESM, you won't be able to use the Expo plugin directly in a CJS-based NestJS project due to this limitation. There is no official compatibility layer or workaround for this in Better Auth right now.

Summary of workarounds:

  • Use an explicit type annotation or cast the plugin to suppress the TS error.
  • Migrate your backend to ESM to use the Expo plugin, or use dynamic import if possible.
  • Keep all Better Auth packages and plugins at matching versions and ensure only one copy exists in node_modules.

Let me know if you need an example ESM migration or more details on dynamic import usage.

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:3677899198 --> @dosubot[bot] commented on GitHub (Dec 20, 2025): <!-- Greeting --> Hi @edw19! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Your TypeScript error (TS2742) happens because the inferred type of `auth` references internal types from dependencies like `better-call`, which aren't exported at the top level—this is a known issue when using plugins like Expo in Better Auth, especially with pnpm or monorepos. The most reliable workaround is to use an explicit type annotation when exporting `auth`, for example: ```ts export const auth = betterAuth(authConfig) as ReturnType<typeof betterAuth<typeof authConfig>>; ``` or, if you want to keep plugin inference, you can cast the plugin as `any` or `BetterAuthPlugin`: ```ts plugins: [expo() as any] ``` or ```ts plugins: [expo() as unknown as BetterAuthPlugin] ``` This will suppress the error, but you may lose some type safety for the plugin itself. Disabling `"declaration"` in your `tsconfig.json` hides the error because TypeScript stops emitting declaration files, but this can impact type safety and portability, and doesn't fix the root cause ([source](https://github.com/better-auth/better-auth/issues/4556)). The Node.js `ERR_REQUIRE_ESM` error is because `@better-auth/expo` is published as an ES module only (`"type": "module"`, main entry is `.mjs`), so it can't be loaded with `require()` in a CommonJS (CJS) context, which is the default for many NestJS projects. To resolve this, you need to either: - Migrate your backend to ESM (set `"type": "module"` in your `package.json`, use `import` instead of `require`, and ensure all dependencies support ESM). - Use dynamic `import()` for the Expo plugin in your code if you must stay on CJS (though this can be tricky with NestJS module loading). - There is no CJS build of the Expo plugin, so aliasing to a CJS version is not possible. The Expo plugin is designed to be used on the server side (including with NestJS) if your backend supports ESM and you add the plugin to your Better Auth config. There is no special NestJS integration, but it works as long as your server can import ESM modules ([source](https://github.com/better-auth/better-auth/issues/6207), [source](https://github.com/better-auth/better-auth/blob/999a830b6fa1da1f8705446482de54767c017030/packages/expo/package.json#L4-L102)). If you can't migrate your backend to ESM, you won't be able to use the Expo plugin directly in a CJS-based NestJS project due to this limitation. There is no official compatibility layer or workaround for this in Better Auth right now. Summary of workarounds: - Use an explicit type annotation or cast the plugin to suppress the TS error. - Migrate your backend to ESM to use the Expo plugin, or use dynamic import if possible. - Keep all Better Auth packages and plugins at matching versions and ensure only one copy exists in `node_modules`. Let me know if you need an example ESM migration or more details on dynamic import usage. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/9a6a0dcb-0d5c-4caa-b85e-80508328c020?feedback_type=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)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=Your%20TypeScript%20error%20%28TS2742%29%20happens%20because%20the%20inferred%20type%20of%20%60auth%60%20references%20internal%20types%20from%20dependencies%20like%20%60better-call%60%2C%20which%20aren%27t%20exported%20at%20the%20top%20level%E2%80%94this%20is%20a%20known%20issue%20when%20using%20plugins%20like%20Expo%20in%20Better%20Auth%2C%20especially%20with%20pnpm%20or%20monorepos.%20The%20most%20reliable%20workaround%20is%20to%20use%20an%20explicit%20type%20annotation%20when%20exporting%20%60auth%60%2C%20for%20example%3A%0A%0A%60%60%60ts%0Aexport%20const%20auth%20%3D%20betterAuth%28authConfig%29%20as%20ReturnType%3Ctypeof%20betterAuth%3Ctypeof%20authConfig%3E%3E%3B%0A%60%60%60%0Aor%2C%20if%20you%20want%20to%20keep%20plugin%20inference%2C%20you%20can%20cast%20the%20plugin%20as%20%60any%60%20or%20%60BetterAuthPlugin%60%3A%0A%60%60%60ts%0Aplugins%3A%20%5Bexpo%28%29%20as%20any%5D%0A%60%60%60%0Aor%0A%60%60%60ts%0Aplugins%3A%20%5Bexpo%28%29%20as%20unknown%20as%20BetterAuthPlugin%5D%0A%60%60%60%0AThis%20will%20suppress%20the%20error%2C%20but%20you%20may%20lose%20some%20type%20safety%20for%20the%20plugin%20itself.%20Disabling%20%60%22declaration%22%60%20in%20your%20%60tsconfig.json%60%20hides%20the%20error%20because%20TypeScript%20stops%20emitting%20declaration%20files%2C%20but%20this%20can%20impact%20type%20safety%20and%20portability%2C%20and%20doesn%27t%20fix%20the%20root%20cause%C2%A0%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/4556%29%29.%0A%0AThe%20Node.js%20%60ERR_REQUIRE_ESM%60%20error%20is%20because%20%60%40better-auth/expo%60%20is%20published%20as%20an%20ES%20module%20only%20%28%60%22type%22%3A%20%22module%22%60%2C%20main%20entry%20is%20%60.mjs%60%29%2C%20so%20it%20can%27t%20be%20loaded%20with%20%60require%28%29%60%20in%20a%20CommonJS%20%28CJS%29%20context%2C%20which%20is%20the%20default%20for%20many%20NestJS%20projects.%20To%20resolve%20this%2C%20you%20need%20to%20either%3A%0A%0A-%20Migrate%20your%20backend%20to%20ESM%20%28set%20%60%22type%22%3A%20%22module%22%60%20in%20your%20%60package.json%60%2C%20use%20%60import%60%20instead%20of%20%60require%60%2C%20and%20ensure%20all%20dependencies%20support%20ESM%29.%0A-%20Use%20dynamic%20%60import%28%29%60%20for%20the%20Expo%20plugin%20in%20your%20code%20if%20you%20must%20stay%20on%20CJS%20%28though%20this%20can%20be%20tricky%20with%20NestJS%20module%20loading%29.%0A-%20There%20is%20no%20CJS%20build%20of%20the%20Expo%20plugin%2C%20so%20aliasing%20to%20a%20CJS%20version%20is%20not%20possible.%0A%0AThe%20Expo%20plugin%20is%20designed%20to%20be%20used%20on%20the%20server%20side%20%28including%20with%20NestJS%29%20if%20your%20backend%20supports%20ESM%20and%20you%20add%20the%20plugin%20to%20your%20Better%20Auth%20config.%20There%20is%20no%20special%20NestJS%20integration%2C%20but%20it%20works%20as%20long%20as%20your%20server%20can%20import%20ESM%20modules%C2%A0%28%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6207%29%2C%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/blob/999a830b6fa1da1f8705446482de54767c017030/packages/expo/package.json%23L4-L102%29%29.%0A%0AIf%20you%20can%27t%20migrate%20your%20backend%20to%20ESM%2C%20you%20won%27t%20be%20able%20to%20use%20the%20Expo%20plugin%20directly%20in%20a%20CJS-based%20NestJS%20project%20due%20to%20this%20limitation.%20There%20is%20no%20official%20compatibility%20layer%20or%20workaround%20for%20this%20in%20Better%20Auth%20right%20now.%0A%0ASummary%20of%20workarounds%3A%0A-%20Use%20an%20explicit%20type%20annotation%20or%20cast%20the%20plugin%20to%20suppress%20the%20TS%20error.%0A-%20Migrate%20your%20backend%20to%20ESM%20to%20use%20the%20Expo%20plugin%2C%20or%20use%20dynamic%20import%20if%20possible.%0A-%20Keep%20all%20Better%20Auth%20packages%20and%20plugins%20at%20matching%20versions%20and%20ensure%20only%20one%20copy%20exists%20in%20%60node_modules%60.%0A%0ALet%20me%20know%20if%20you%20need%20an%20example%20ESM%20migration%20or%20more%20details%20on%20dynamic%20import%20usage.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&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/6909)
Author
Owner

@ping-maxwell commented on GitHub (Jan 7, 2026):

Hello, @edw19 please try out the latest version of better-auth and let me know how it goes!

Additionally, if that doesn't resolve your issue please provide me your tsconfig.json file.

<!-- gh-comment-id:3719079082 --> @ping-maxwell commented on GitHub (Jan 7, 2026): Hello, @edw19 please try out the latest version of better-auth and let me know how it goes! Additionally, if that doesn't resolve your issue please provide me your tsconfig.json file.
Author
Owner

@ping-maxwell commented on GitHub (Feb 11, 2026):

closing from inactivity

<!-- gh-comment-id:3882939199 --> @ping-maxwell commented on GitHub (Feb 11, 2026): closing from inactivity
Author
Owner

@github-actions[bot] commented on GitHub (Apr 1, 2026):

This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.

<!-- gh-comment-id:4166559649 --> @github-actions[bot] commented on GitHub (Apr 1, 2026): This issue has been locked as it was closed more than 7 days ago. If you're experiencing a similar problem or you have additional context, please open a new issue and reference this one.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19299