[GH-ISSUE #6015] drizzleAdapter for the bun-sql provider #19032

Closed
opened 2026-04-15 17:48:39 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @losh11 on GitHub (Nov 16, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6015

Is this suited for github?

  • Yes, this is suited for github

My backend uses Drizzle ORM to connect to a postgresdb, using the bun-sql adaptor.
Example:

import { drizzle } from "drizzle-orm/bun-sql";

export const postgresdb = drizzle({
  connection: DATABASE_URL,
  casing: "snake_case",
});

Basically nothing out of the ordinary...

I'd like for the better-auth drizzleAdaptor to also be able to use the bun-sql as the driver.

Describe the solution you'd like

Ideally just to be able to select the provider "bun".

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";

import { postgresdb } from "..";

export const auth = betterAuth({
  database: drizzleAdapter(postgresdb, {
    provider: "pg",
  }),
});

Additional context

Currently trying to generate migrations as part of initial setup fails like this:

$ bunx @better-auth/cli generate
2025-11-16T07:28:45.873Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'bun'
Require stack:
- /Users/loshan/Repos/repo/server/node_modules/drizzle-orm/bun-sql/driver.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15)
    at Function.resolve (node:internal/modules/helpers:146:19)
    at jitiResolve (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:148703)
    at jitiRequire (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:150290)
    at import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158307)
    at /Users/loshan/Repos/ltc/nexus-dashboard/server/node_modules/drizzle-orm/bun-sql/driver.js:1:247
    at eval_evalModule (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:155533)
    at /private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:154214
    at async import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301)
    at async /Users/loshan/Repos/ltc/nexus-dashboard/server/node_modules/drizzle-orm/bun-sql/index.js:1:186
    at async import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301)
    at async /Users/loshan/Repos/ltc/nexus-dashboard/server/src/index.ts:4:15
    at async import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301)
    at async /Users/loshan/Repos/ltc/nexus-dashboard/server/src/utils/auth.ts:4:9
    at async Function.import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301)
    at async resolveConfig (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/c12/dist/index.mjs:320:20)
    at async loadConfig (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/c12/dist/index.mjs:149:22)
    at async getConfig (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:1990:30)
    at async Command.generateAction (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:2705:18) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/loshan/Repos/repo/server/node_modules/drizzle-orm/bun-sql/driver.js'
  ]
}
Originally created by @losh11 on GitHub (Nov 16, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6015 ### Is this suited for github? - [x] Yes, this is suited for github ### Is your feature request related to a problem? Please describe. My backend uses Drizzle ORM to connect to a postgresdb, using the bun-sql adaptor. Example: ```drizzle.config.ts import { drizzle } from "drizzle-orm/bun-sql"; export const postgresdb = drizzle({ connection: DATABASE_URL, casing: "snake_case", }); ``` Basically nothing out of the ordinary... I'd like for the better-auth drizzleAdaptor to also be able to use the bun-sql as the driver. ### Describe the solution you'd like Ideally just to be able to select the provider "bun". ``` import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { postgresdb } from ".."; export const auth = betterAuth({ database: drizzleAdapter(postgresdb, { provider: "pg", }), }); ``` ### Additional context Currently trying to generate migrations as part of initial setup fails like this: ```bash $ bunx @better-auth/cli generate 2025-11-16T07:28:45.873Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'bun' Require stack: - /Users/loshan/Repos/repo/server/node_modules/drizzle-orm/bun-sql/driver.js at Function._resolveFilename (node:internal/modules/cjs/loader:1225:15) at Function.resolve (node:internal/modules/helpers:146:19) at jitiResolve (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:148703) at jitiRequire (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:150290) at import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158307) at /Users/loshan/Repos/ltc/nexus-dashboard/server/node_modules/drizzle-orm/bun-sql/driver.js:1:247 at eval_evalModule (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:155533) at /private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:154214 at async import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301) at async /Users/loshan/Repos/ltc/nexus-dashboard/server/node_modules/drizzle-orm/bun-sql/index.js:1:186 at async import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301) at async /Users/loshan/Repos/ltc/nexus-dashboard/server/src/index.ts:4:15 at async import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301) at async /Users/loshan/Repos/ltc/nexus-dashboard/server/src/utils/auth.ts:4:9 at async Function.import (/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301) at async resolveConfig (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/c12/dist/index.mjs:320:20) at async loadConfig (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/c12/dist/index.mjs:149:22) at async getConfig (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:1990:30) at async Command.generateAction (file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs:2705:18) { code: 'MODULE_NOT_FOUND', requireStack: [ '/Users/loshan/Repos/repo/server/node_modules/drizzle-orm/bun-sql/driver.js' ] } ```
GiteaMirror added the locked label 2026-04-15 17:48:39 -05:00
Author
Owner

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

Hi there! Thank you for reporting the issue with using "bun-sql" via the drizzle adapter. It appears that the error ("Cannot find module 'bun'") is occurring because the current adapter configuration expects the traditional PostgreSQL driver (i.e. using "pg"), and native support for bun-sql isn't available yet. One workaround is to ensure the Bun runtime is fully available in your environment, or alternatively, configure your adapter to use a supported driver while we work on adding explicit support for bun-sql. We're aware of similar issues with module resolution when using Bun, and it's something on our roadmap for a future update. Can you share more about your development setup and timeline so we can better assist? tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3538242047 --> @better-auth-agent[bot] commented on GitHub (Nov 16, 2025): Hi there! Thank you for reporting the issue with using "bun-sql" via the drizzle adapter. It appears that the error ("Cannot find module 'bun'") is occurring because the current adapter configuration expects the traditional PostgreSQL driver (i.e. using "pg"), and native support for bun-sql isn't available yet. One workaround is to ensure the Bun runtime is fully available in your environment, or alternatively, configure your adapter to use a supported driver while we work on adding explicit support for bun-sql. We're aware of similar issues with module resolution when using Bun, and it's something on our roadmap for a future update. Can you share more about your development setup and timeline so we can better assist? tag @better-auth-agent if you would like an answer from the Agent <!-- 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)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19032