[GH-ISSUE #3369] ERR_REQUIRE_ESM on better-auth 1.2.10 (not 1.2.11+) on Vercel Deployment #18212

Closed
opened 2026-04-15 16:36:05 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @Maxime-NS on GitHub (Jul 14, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3369

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create a standard NextJS project with create-next-app
  2. Install better-auth version 1.2.10
  3. Run the project and import/use better-auth
  4. Try deploying the project on Vercel

Current vs. Expected behavior

Expected : The build passes on Vercel but opening up the project shouldn't trigger a internal server error (500) with ERR_REQUIRE_ESM
Current : The build passes on Vercel but opening up the project triggers the ERR_REQUIRE_ESM error

What version of Better Auth are you using?

1.2.10

Provide environment information

- OS: Windows
- Deployment : Vercel
- Better Auth : 1.2.10

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

Backend

Auth config (if applicable)


Additional context

I'm also seeing the same error when trying to launch a basic Payload CMS project with npx create-payload-app@latest and deploying it on Vercel. I saw the thread here but after fixing the version to 1.2.10, I'm still seeing the same error.

Originally created by @Maxime-NS on GitHub (Jul 14, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3369 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create a standard NextJS project with create-next-app 2. Install better-auth version 1.2.10 3. Run the project and import/use better-auth 4. Try deploying the project on Vercel ### Current vs. Expected behavior **Expected** : The build passes on Vercel but opening up the project shouldn't trigger a internal server error (500) with ERR_REQUIRE_ESM **Current** : The build passes on Vercel but opening up the project triggers the ERR_REQUIRE_ESM error ### What version of Better Auth are you using? 1.2.10 ### Provide environment information ```bash - OS: Windows - Deployment : Vercel - Better Auth : 1.2.10 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context I'm also seeing the same error when trying to launch a basic Payload CMS project with ```npx create-payload-app@latest``` and deploying it on Vercel. I saw the thread [here](https://github.com/better-auth/better-auth/issues/3260) but after fixing the version to 1.2.10, I'm still seeing the same error.
GiteaMirror added the locked label 2026-04-15 16:36:05 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jul 14, 2025):

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

The ERR_REQUIRE_ESM error with better-auth 1.2.10 on Vercel happens because the package is published as an ES module ("type": "module" in package.json) and uses ESM-style exports throughout its codebase—even though it tries to provide both ESM and CommonJS entry points in its exports field. Many deployment environments (like Vercel with Next.js or Payload CMS) may not resolve these dual exports as intended, especially if they expect CommonJS, leading to this runtime error. This is the same root cause as in 1.2.11+, but pinning to 1.2.10 doesn't always help because 1.2.10 is also fundamentally ESM-oriented and lacks a true CommonJS compatibility layer see details.

There isn't an official workaround for using better-auth 1.2.10 in a CommonJS environment on Vercel. The only reliable solution is to ensure your project and deployment environment are fully ESM-compatible. If you must use CommonJS, you could try upgrading your Node.js runtime to a version that supports require(esm) by default (Node 20.19.0+, 22.12.0+, or 23.0.0+), but this is not guaranteed to work in all deployment scenarios and is not officially documented for better-auth 1.2.10 reference.

If you need to stick with 1.2.10 and CommonJS, there is unfortunately no supported workaround. Migrating your project to ESM or waiting for official CJS support are the only robust paths forward.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

<!-- gh-comment-id:3068003203 --> @dosubot[bot] commented on GitHub (Jul 14, 2025): <!-- Greeting --> Hi @Maxime-NS! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The ERR_REQUIRE_ESM error with better-auth 1.2.10 on Vercel happens because the package is published as an ES module (`"type": "module"` in package.json) and uses ESM-style exports throughout its codebase—even though it tries to provide both ESM and CommonJS entry points in its exports field. Many deployment environments (like Vercel with Next.js or Payload CMS) may not resolve these dual exports as intended, especially if they expect CommonJS, leading to this runtime error. This is the same root cause as in 1.2.11+, but pinning to 1.2.10 doesn't always help because 1.2.10 is also fundamentally ESM-oriented and lacks a true CommonJS compatibility layer [see details](https://github.com/better-auth/better-auth/issues/3260). There isn't an official workaround for using better-auth 1.2.10 in a CommonJS environment on Vercel. The only reliable solution is to ensure your project and deployment environment are fully ESM-compatible. If you must use CommonJS, you could try upgrading your Node.js runtime to a version that supports `require(esm)` by default (Node 20.19.0+, 22.12.0+, or 23.0.0+), but this is not guaranteed to work in all deployment scenarios and is not officially documented for better-auth 1.2.10 [reference](https://github.com/better-auth/better-auth/issues/3260). If you need to stick with 1.2.10 and CommonJS, there is unfortunately no supported workaround. Migrating your project to ESM or waiting for official CJS support are the only robust paths forward. <!-- 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/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/166aca47-7cd7-48e2-b53b-a1ef4c06c989?feedback_type=other)</sup>&nbsp;&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/3369)
Author
Owner

@Kinfe123 commented on GitHub (Jul 15, 2025):

if the above does not solve your issue. can you please share your package.json and tsconfig.json ?

<!-- gh-comment-id:3072968486 --> @Kinfe123 commented on GitHub (Jul 15, 2025): if the above does not solve your issue. can you please share your package.json and tsconfig.json ?
Author
Owner

@Maxime-NS commented on GitHub (Jul 15, 2025):

Hi ! Thanks for answering. Yes so here was my package.json :

{
  "name": "ryb",
  "version": "0.1.0",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "cross-env NODE_OPTIONS=--no-deprecation next build ",
    "dev": "cross-env NODE_OPTIONS=--no-deprecation next dev --turbo",
    "generate:importmap": "cross-env NODE_OPTIONS=--no-deprecation payload generate:importmap",
    "generate:types": "cross-env NODE_OPTIONS=--no-deprecation payload generate:types",
    "lint": "cross-env NODE_OPTIONS=--no-deprecation next lint --quiet",
    "lint:fix": "cross-env NODE_OPTIONS=--no-deprecation next lint --fix",
    "payload": "cross-env NODE_OPTIONS=--no-deprecation payload",
    "start": "cross-env NODE_OPTIONS=--no-deprecation next start"
  },
  "dependencies": {
    "@hookform/resolvers": "^5.1.1",
    "@payloadcms/db-postgres": "3.39.1",
    "@payloadcms/next": "3.39.1",
    "@payloadcms/richtext-lexical": "3.39.1",
    "@radix-ui/react-label": "^2.1.7",
    "@radix-ui/react-slot": "^1.2.3",
    "better-auth": "^1.2.12",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "cross-env": "^7.0.3",
    "graphql": "^16.11.0",
    "lucide-react": "^0.525.0",
    "next": "15.3.5",
    "payload": "3.39.1",
    "payload-auth": "^1.6.4",
    "react": "^19.0.0",
    "react-dom": "^19.0.0",
    "react-hook-form": "^7.60.0",
    "tailwind-merge": "^3.3.1",
    "zod": "^4.0.5"
  },
  "devDependencies": {
    "@eslint/eslintrc": "^3",
    "@tailwindcss/postcss": "^4",
    "@types/node": "^20",
    "@types/react": "^19",
    "@types/react-dom": "^19",
    "eslint": "^9",
    "eslint-config-next": "15.2.0",
    "tailwindcss": "^4",
    "tw-animate-css": "^1.3.5",
    "typescript": "^5"
  }
}

And the tsconfig.json :

{
  "compilerOptions": {
    "target": "ES2017",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "paths": {
      "@/*": [
        "./src/*"
      ],
      "@payload-config": [
        "./src/payload.config.ts"
      ]
    }
  },
  "include": [
    "next-env.d.ts",
    "/*.ts",
    "/*.tsx",
    ".next/types//*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

I managed to resolve the issue yesterday by downgrading next version to 15.2.0. It's probably possible to downgrade to a more recent version of next (for better turbopack support). I unfortunately didn't have time to investigate whether the problem comes from inside next r a dependency of next.

<!-- gh-comment-id:3074191442 --> @Maxime-NS commented on GitHub (Jul 15, 2025): Hi ! Thanks for answering. Yes so here was my package.json : ``` { "name": "ryb", "version": "0.1.0", "private": true, "type": "module", "scripts": { "build": "cross-env NODE_OPTIONS=--no-deprecation next build ", "dev": "cross-env NODE_OPTIONS=--no-deprecation next dev --turbo", "generate:importmap": "cross-env NODE_OPTIONS=--no-deprecation payload generate:importmap", "generate:types": "cross-env NODE_OPTIONS=--no-deprecation payload generate:types", "lint": "cross-env NODE_OPTIONS=--no-deprecation next lint --quiet", "lint:fix": "cross-env NODE_OPTIONS=--no-deprecation next lint --fix", "payload": "cross-env NODE_OPTIONS=--no-deprecation payload", "start": "cross-env NODE_OPTIONS=--no-deprecation next start" }, "dependencies": { "@hookform/resolvers": "^5.1.1", "@payloadcms/db-postgres": "3.39.1", "@payloadcms/next": "3.39.1", "@payloadcms/richtext-lexical": "3.39.1", "@radix-ui/react-label": "^2.1.7", "@radix-ui/react-slot": "^1.2.3", "better-auth": "^1.2.12", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "cross-env": "^7.0.3", "graphql": "^16.11.0", "lucide-react": "^0.525.0", "next": "15.3.5", "payload": "3.39.1", "payload-auth": "^1.6.4", "react": "^19.0.0", "react-dom": "^19.0.0", "react-hook-form": "^7.60.0", "tailwind-merge": "^3.3.1", "zod": "^4.0.5" }, "devDependencies": { "@eslint/eslintrc": "^3", "@tailwindcss/postcss": "^4", "@types/node": "^20", "@types/react": "^19", "@types/react-dom": "^19", "eslint": "^9", "eslint-config-next": "15.2.0", "tailwindcss": "^4", "tw-animate-css": "^1.3.5", "typescript": "^5"   } } ``` And the tsconfig.json : ``` { "compilerOptions": { "target": "ES2017", "lib": [ "dom", "dom.iterable", "esnext" ], "allowJs": true, "skipLibCheck": true, "strict": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "bundler", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "plugins": [ { "name": "next" } ], "paths": { "@/*": [ "./src/*" ], "@payload-config": [ "./src/payload.config.ts" ] } }, "include": [ "next-env.d.ts", "/*.ts", "/*.tsx", ".next/types//*.ts" ], "exclude": [ "node_modules"   ] } ``` I managed to resolve the issue yesterday by downgrading next version to ```15.2.0```. It's probably possible to downgrade to a more recent version of next (for better turbopack support). I unfortunately didn't have time to investigate whether the problem comes from inside next r a dependency of next.
Author
Owner

@Kinfe123 commented on GitHub (Jul 17, 2025):

do you make any configuration change on the vercel about nodejs versions ? and it is works fine locally right ?

<!-- gh-comment-id:3082298019 --> @Kinfe123 commented on GitHub (Jul 17, 2025): do you make any configuration change on the vercel about nodejs versions ? and it is works fine locally right ?
Author
Owner

@Kinfe123 commented on GitHub (Jul 31, 2025):

closing this as duplicate as dosu bot mentioned it. but if you think this is actually an issue please tag me. i will reopen it

<!-- gh-comment-id:3139759322 --> @Kinfe123 commented on GitHub (Jul 31, 2025): closing this as duplicate as dosu bot mentioned it. but if you think this is actually an issue please tag me. i will reopen it
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18212