[GH-ISSUE #1694] better-auth cant read "bun" module to import postgresql #8870

Closed
opened 2026-04-13 04:06:50 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @sourabratabose on GitHub (Mar 5, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1694

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

import { postgres } from "bun";
import { drizzle } from "drizzle-orm/bun-sql";
import * as schema from "./schema";

const client = new postgres(process.env.DB_URL!);

const db = drizzle({ client, logger: true, schema });

export default db;

Better-auth cli can't resolve bun module. I use bun for my daily ts/js driver and drizzle works fine with it. Bun.postgres() call only worsens the issue as bun runtime calls import other bun modules during execution and throws the same error.

Current vs. Expected behavior

No migrations files generated from better-auth/cli as it encounters error in finding bun modules. Expected behavior is files generated in drizzle migrations output folder.

What version of Better Auth are you using?

1.2.3

Provide environment information

- Runtime is Bun
- OS is Windows 11

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

Backend

Auth config (if applicable)

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

const auth = betterAuth({
  database: drizzleAdapter(db, {
    provider: "pg",
  }),
  emailAndPassword: {
    enabled: true,
  },
  secondaryStorage: {
		get: async (key) => {
			const value = await redis.get(key);
			return value ? JSON.stringify(value) : null;
		},
		set: async (key, value, ttl) => {
			if (ttl) await redis.set(key, value, { EX: ttl });
			else await redis.set(key, value);
		},
		delete: async (key) => {
			await redis.del(key);
		}
	},
  socialProviders: {
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
    },
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    },
  },
});

export default auth;

Additional context

No response

Originally created by @sourabratabose on GitHub (Mar 5, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1694 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ``` import { postgres } from "bun"; import { drizzle } from "drizzle-orm/bun-sql"; import * as schema from "./schema"; const client = new postgres(process.env.DB_URL!); const db = drizzle({ client, logger: true, schema }); export default db; ``` Better-auth cli can't resolve bun module. I use bun for my daily ts/js driver and drizzle works fine with it. Bun.postgres() call only worsens the issue as bun runtime calls import other bun modules during execution and throws the same error. ### Current vs. Expected behavior No migrations files generated from better-auth/cli as it encounters error in finding bun modules. Expected behavior is files generated in drizzle migrations output folder. ### What version of Better Auth are you using? 1.2.3 ### Provide environment information ```bash - Runtime is Bun - OS is Windows 11 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import db from "../db/db"; import redis from "../db/redis"; const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), emailAndPassword: { enabled: true, }, secondaryStorage: { get: async (key) => { const value = await redis.get(key); return value ? JSON.stringify(value) : null; }, set: async (key, value, ttl) => { if (ttl) await redis.set(key, value, { EX: ttl }); else await redis.set(key, value); }, delete: async (key) => { await redis.del(key); } }, socialProviders: { github: { clientId: process.env.GITHUB_CLIENT_ID!, clientSecret: process.env.GITHUB_CLIENT_SECRET!, }, google: { clientId: process.env.GOOGLE_CLIENT_ID!, clientSecret: process.env.GOOGLE_CLIENT_SECRET!, }, }, }); export default auth; ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:06:50 -05:00
Author
Owner

@varo6 commented on GitHub (Mar 9, 2025):

this can be solved by passing the --bun prefix

bunx --bun @better-auth/cli generate 

and if better-auth can't find the config file add the --config path/to/auth.ts

<!-- gh-comment-id:2709007068 --> @varo6 commented on GitHub (Mar 9, 2025): this can be solved by passing the --bun prefix ```bash bunx --bun @better-auth/cli generate ``` and if better-auth can't find the config file add the --config path/to/auth.ts
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8870