[GH-ISSUE #7438] Regression: Zod locales re-included in bundle + unexpected kysely dependency #10812

Closed
opened 2026-04-13 07:10:12 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @sabaturgay on GitHub (Jan 17, 2026).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/7438

Originally assigned to: @himself65 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Install better-auth@1.4.4 and bundle a Cloudflare Worker using esbuild.
  2. Upgrade to better-auth@1.4.12 and rebundle the same Worker with the same build configuration.
  3. Compare the generated esbuild metafile (--metafile) between the two builds.

Current vs. Expected behavior

A previously fixed bundling issue has regressed.
Between v1.4.4 → v1.4.12, Zod locale files are being bundled again, and kysely is also pulled in unexpectedly, even when using better-auth/minimal with Drizzle.

This negates an earlier bundle-size optimization.

What version of Better Auth are you using?

1.4.12

System info

{
  "node": {
    "version": "v22.14.0",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.3.2"
  },
  "frameworks": [
    {
      "name": "react",
      "version": "19.1.0"
    },
    {
      "name": "hono",
      "version": "4.11.4"
    }
  ],
  "databases": [
    {
      "name": "drizzle",
      "version": "0.45.1"
    }
  ],
  "betterAuth": {
    "version": "1.4.4",
    "config": null
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @sabaturgay on GitHub (Jan 17, 2026). Original GitHub issue: https://github.com/better-auth/better-auth/issues/7438 Originally assigned to: @himself65 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Install `better-auth@1.4.4` and bundle a Cloudflare Worker using esbuild. 2. Upgrade to `better-auth@1.4.12` and rebundle the same Worker with the same build configuration. 3. Compare the generated `esbuild` metafile (`--metafile`) between the two builds. ### Current vs. Expected behavior A previously fixed bundling issue has regressed. Between **v1.4.4 → v1.4.12**, Zod locale files are being bundled again, and `kysely` is also pulled in unexpectedly, even when using `better-auth/minimal` with Drizzle. This negates an earlier [bundle-size optimization](https://github.com/better-auth/better-auth/pull/5995). ### What version of Better Auth are you using? 1.4.12 ### System info ```bash { "node": { "version": "v22.14.0", "env": "development" }, "packageManager": { "name": "bun", "version": "1.3.2" }, "frameworks": [ { "name": "react", "version": "19.1.0" }, { "name": "hono", "version": "4.11.4" } ], "databases": [ { "name": "drizzle", "version": "0.45.1" } ], "betterAuth": { "version": "1.4.4", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 07:10:12 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Jan 17, 2026):

It looks like you've raised an issue related to the unexpected inclusion of Zod locales and the kysely dependency when bundling after upgrading to better-auth@1.4.12.

From previous discussions in the community, it has been noted that there were regression issues with the bundling behavior, particularly concerning unnecessary server-side dependencies being included in client bundles. The problem seems to stem from the manner in which the better-auth/minimal package is set up to optimize bundle sizes when kysely is not needed, yet kysely is still appearing unexpectedly in your build.

To address the issue, you might want to:

  1. Ensure you are using the better-auth/minimal package correctly.
  2. Check if there are any updated discussions or patches specifically addressing this regression since similar issues have been reported in the past.
  3. Additionally, you may want to monitor this issue for any forthcoming solutions or ask directly in the community if similar problems have been encountered by others.

For persisting issues or if you require deeper insights specific to your setup, consider tagging the members of the Better Auth team, Beka and Max, who might provide more technical clarification on this behavior.

Is there anything else specific you need help with in relation to your bundling configuration?

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

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3763663397 --> @better-auth-agent[bot] commented on GitHub (Jan 17, 2026): It looks like you've raised an issue related to the unexpected inclusion of `Zod` locales and the `kysely` dependency when bundling after upgrading to `better-auth@1.4.12`. From previous discussions in the community, it has been noted that there were regression issues with the bundling behavior, particularly concerning unnecessary server-side dependencies being included in client bundles. The problem seems to stem from the manner in which the `better-auth/minimal` package is set up to optimize bundle sizes when `kysely` is not needed, yet `kysely` is still appearing unexpectedly in your build. To address the issue, you might want to: 1. Ensure you are using the `better-auth/minimal` package correctly. 2. Check if there are any updated discussions or patches specifically addressing this regression since similar issues have been reported in the past. 3. Additionally, you may want to monitor this issue for any forthcoming solutions or ask directly in the community if similar problems have been encountered by others. For persisting issues or if you require deeper insights specific to your setup, consider tagging the members of the Better Auth team, Beka and Max, who might provide more technical clarification on this behavior. Is there anything else specific you need help with in relation to your bundling configuration? _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/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@himself65 commented on GitHub (Jan 18, 2026):

This seems like a regression. Let me check it

<!-- gh-comment-id:3764881628 --> @himself65 commented on GitHub (Jan 18, 2026): This seems like a regression. Let me check it
Author
Owner

@himself65 commented on GitHub (Jan 18, 2026):

@claude can you check the issue and open a PR for it?

<!-- gh-comment-id:3764881876 --> @himself65 commented on GitHub (Jan 18, 2026): @claude can you check the issue and open a PR for it?
Author
Owner

@github-actions[bot] commented on GitHub (Jan 18, 2026):

Claude finished @himself65's task in 4m 39s —— View jobclaude/issue-7438-20260118-0406Create PR ➔


Fix implemented successfully ✓

  • Gather context about the issue and previous fix
  • Investigate what changed between v1.4.4 and v1.4.12
  • Find where Zod locales are being included
  • Find why Kysely is being pulled in
  • Implement fixes
  • Run type checking and linting
  • Commit and push changes
  • Provide PR URL

Root Cause

The bundling regression was caused by the way db/index.ts barrel exports are structured:

  1. Kysely bundling issue: db/index.ts re-exports get-migration.ts which directly imports kysely:

    • get-migration.ts:18 - import { sql } from "kysely";
    • When init-minimal.ts imports from ../db, bundlers follow the import chain and pull in the entire db/index.ts module
    • This includes get-migration.ts with its kysely dependency
  2. Zod bundling issue: Similarly, db/index.ts re-exports to-zod.ts which imports zod:

    • to-zod.ts:3 - import * as z from "zod";
    • This gets bundled even when using better-auth/minimal with Drizzle

Solution

Updated imports to avoid the barrel export and target specific modules:

  1. src/context/init-minimal.ts - Import getBaseAdapter from ../db/adapter-base instead of ../db
  2. src/types/models.ts - Import type utilities from ../db/field instead of ../db
  3. src/client/types.ts - Import type utilities from ../db/field instead of ../db

This ensures the minimal export path (better-auth/minimal) only pulls in necessary code without heavy dependencies like kysely and zod.

Create Pull Request


Branch: claude/issue-7438-20260118-0406

<!-- gh-comment-id:3764882008 --> @github-actions[bot] commented on GitHub (Jan 18, 2026): **Claude finished @himself65's task in 4m 39s** —— [View job](https://github.com/better-auth/better-auth/actions/runs/21105746603) • [`claude/issue-7438-20260118-0406`](https://github.com/better-auth/better-auth/tree/claude/issue-7438-20260118-0406) • [Create PR ➔](https://github.com/better-auth/better-auth/compare/canary...claude/issue-7438-20260118-0406?quick_pull=1&title=fix(minimal)%3A%20prevent%20kysely%20and%20zod%20from%20being%20bundled%20in%20minimal%20mode&body=This%20PR%20fixes%20a%20bundling%20regression%20where%20%60kysely%60%20and%20%60zod%60%20dependencies%20were%20being%20included%20in%20bundles%20when%20using%20%60better-auth%2Fminimal%60.%0A%0A%23%23%20Problem%0A%0ABetween%20v1.4.4%20%E2%86%92%20v1.4.12%2C%20Zod%20locale%20files%20and%20kysely%20were%20being%20bundled%20again%2C%20even%20when%20using%20%60better-auth%2Fminimal%60%20with%20Drizzle.%20This%20negated%20an%20earlier%20bundle-size%20optimization.%0A%0AThe%20issue%20was%20caused%20by%20importing%20from%20%60..%2Fdb%60%20which%20pulls%20in%20the%20entire%20%60db%2Findex.ts%60%20barrel%20export%2C%20including%3A%0A-%20%60db%2Fget-migration.ts%60%20(which%20imports%20kysely)%0A-%20%60db%2Fto-zod.ts%60%20(which%20imports%20zod)%0A%0A%23%23%20Changes%0A%0A-%20Update%20%60init-minimal.ts%60%20to%20import%20%60getBaseAdapter%60%20from%20%60db%2Fadapter-base%60%0A-%20Update%20%60types%2Fmodels.ts%60%20to%20import%20type%20utilities%20from%20%60db%2Ffield%60%0A-%20Update%20%60client%2Ftypes.ts%60%20to%20import%20type%20utilities%20from%20%60db%2Ffield%60%0A%0AThis%20ensures%20the%20minimal%20export%20path%20only%20pulls%20in%20necessary%20code%20without%20heavy%20dependencies.%0A%0AFixes%20%237438%0A%0A---%0A%0AGenerated%20with%20%5BClaude%20Code%5D(https%3A%2F%2Fclaude.ai%2Fcode)) --- ### Fix implemented successfully ✓ - [x] Gather context about the issue and previous fix - [x] Investigate what changed between v1.4.4 and v1.4.12 - [x] Find where Zod locales are being included - [x] Find why Kysely is being pulled in - [x] Implement fixes - [x] Run type checking and linting - [x] Commit and push changes - [x] Provide PR URL --- ### Root Cause The bundling regression was caused by the way `db/index.ts` barrel exports are structured: 1. **Kysely bundling issue**: `db/index.ts` re-exports `get-migration.ts` which directly imports `kysely`: - `get-migration.ts:18` - `import { sql } from "kysely";` - When `init-minimal.ts` imports from `../db`, bundlers follow the import chain and pull in the entire `db/index.ts` module - This includes `get-migration.ts` with its kysely dependency 2. **Zod bundling issue**: Similarly, `db/index.ts` re-exports `to-zod.ts` which imports `zod`: - `to-zod.ts:3` - `import * as z from "zod";` - This gets bundled even when using `better-auth/minimal` with Drizzle ### Solution Updated imports to avoid the barrel export and target specific modules: 1. `src/context/init-minimal.ts` - Import `getBaseAdapter` from `../db/adapter-base` instead of `../db` 2. `src/types/models.ts` - Import type utilities from `../db/field` instead of `../db` 3. `src/client/types.ts` - Import type utilities from `../db/field` instead of `../db` This ensures the minimal export path (`better-auth/minimal`) only pulls in necessary code without heavy dependencies like `kysely` and `zod`. ### Create Pull Request --- • [Branch: claude/issue-7438-20260118-0406](https://github.com/better-auth/better-auth/tree/claude/issue-7438-20260118-0406)
Author
Owner

@himself65 commented on GitHub (Jan 19, 2026):

This is a regression. Im fixing it

<!-- gh-comment-id:3766145844 --> @himself65 commented on GitHub (Jan 19, 2026): This is a regression. Im fixing 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#10812