[GH-ISSUE #2155] Failed to run migration with Bun #9071

Closed
opened 2026-04-13 04:22:02 -05:00 by GiteaMirror · 24 comments
Owner

Originally created by @Arsik0153 on GitHub (Apr 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/2155

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Create express-js project with typescript and bun
  2. Integrate better-auth with bun:sqlite like this:
import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db } from '../database';
import { expo } from '@better-auth/expo';

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: 'sqlite',
    }),
    plugins: [expo()],
    emailAndPassword: {
        enabled: true,
    },
});

//db
import { drizzle } from 'drizzle-orm/bun-sqlite';
import { Database } from 'bun:sqlite';
import * as authSchema from './schema/auth';
import * as transactionSchema from './schema/transaction';

const sqlite = new Database('sqlite.db');
export const db = drizzle(sqlite, {
    schema: {
        ...authSchema,
        ...transactionSchema,
    },
});

sqlite.exec('PRAGMA foreign_keys = ON;');
  1. Run bunx @better-auth/cli@latest generate

Current vs. Expected behavior

Current behavior:
I am getting this error:

mymac@macbook MyWallet-backend % bunx @better-auth/cli@latest generate
2025-04-06T17:14:40.319Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'bun:sqlite'
Require stack:
- /Users/*****/MyWallet-backend/node_modules/drizzle-orm/bun-sqlite/driver.js

Expected behavior:
It should successfully run migration script

What version of Better Auth are you using?

^1.2.5

Provide environment information

- OS: MacOS 14.7.4
- Environment: Bun v1.2.8

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 '../database';
import { expo } from '@better-auth/expo';

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: 'sqlite',
    }),
    plugins: [expo()],
    emailAndPassword: {
        enabled: true,
    },
});

Additional context

Package json:

{
    "name": "mywallet-backend",
    "version": "1.0.0",
    "description": "Backend for MyWallet React Native app",
    "main": "src/index.ts",
    "scripts": {
        "start": "bun run src/index.ts",
        "dev": "bun --watch run src/index.ts",
        "build": "tsc",
        "db:generate": "drizzle-kit generate:sqlite",
        "db:push": "drizzle-kit push:sqlite",
        "db:studio": "drizzle-kit studio",
        "lint": "eslint . --ext .ts",
        "format": "prettier --write \"src/**/*.ts\""
    },
    "keywords": [
        "wallet",
        "backend",
        "express",
        "drizzle",
        "sqlite"
    ],
    "author": "",
    "license": "ISC",
    "type": "module",
    "devDependencies": {
        "@types/bun": "^1.2.8",
        "@typescript-eslint/eslint-plugin": "^8.29.0",
        "@typescript-eslint/parser": "^8.29.0",
        "eslint": "^9.24.0",
        "prettier": "^3.5.3"
    },
    "peerDependencies": {
        "typescript": "^5.8.3"
    },
    "dependencies": {
        "@better-auth/cli": "^1.2.5",
        "@better-auth/expo": "^1.2.5",
        "@types/cors": "^2.8.17",
        "@types/express": "^5.0.1",
        "@types/node": "^22.14.0",
        "better-auth": "^1.2.5",
        "better-sqlite3": "^11.9.1",
        "cors": "^2.8.5",
        "dotenv": "^16.4.7",
        "drizzle-kit": "^0.30.6",
        "drizzle-orm": "^0.41.0",
        "express": "^5.1.0",
        "helmet": "^8.1.0",
        "ts-node-dev": "^2.0.0",
        "zod": "^3.24.2"
    }
}
Originally created by @Arsik0153 on GitHub (Apr 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/2155 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Create express-js project with typescript and **bun** 2. Integrate better-auth with bun:sqlite like this: ```typescript import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { db } from '../database'; import { expo } from '@better-auth/expo'; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'sqlite', }), plugins: [expo()], emailAndPassword: { enabled: true, }, }); //db import { drizzle } from 'drizzle-orm/bun-sqlite'; import { Database } from 'bun:sqlite'; import * as authSchema from './schema/auth'; import * as transactionSchema from './schema/transaction'; const sqlite = new Database('sqlite.db'); export const db = drizzle(sqlite, { schema: { ...authSchema, ...transactionSchema, }, }); sqlite.exec('PRAGMA foreign_keys = ON;'); ``` 3. Run ```bunx @better-auth/cli@latest generate``` ### Current vs. Expected behavior Current behavior: I am getting this error: ``` mymac@macbook MyWallet-backend % bunx @better-auth/cli@latest generate 2025-04-06T17:14:40.319Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'bun:sqlite' Require stack: - /Users/*****/MyWallet-backend/node_modules/drizzle-orm/bun-sqlite/driver.js ``` Expected behavior: It should successfully run migration script ### What version of Better Auth are you using? ^1.2.5 ### Provide environment information ```bash - OS: MacOS 14.7.4 - Environment: Bun v1.2.8 ``` ### 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 '../database'; import { expo } from '@better-auth/expo'; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: 'sqlite', }), plugins: [expo()], emailAndPassword: { enabled: true, }, }); ``` ### Additional context Package json: ```json { "name": "mywallet-backend", "version": "1.0.0", "description": "Backend for MyWallet React Native app", "main": "src/index.ts", "scripts": { "start": "bun run src/index.ts", "dev": "bun --watch run src/index.ts", "build": "tsc", "db:generate": "drizzle-kit generate:sqlite", "db:push": "drizzle-kit push:sqlite", "db:studio": "drizzle-kit studio", "lint": "eslint . --ext .ts", "format": "prettier --write \"src/**/*.ts\"" }, "keywords": [ "wallet", "backend", "express", "drizzle", "sqlite" ], "author": "", "license": "ISC", "type": "module", "devDependencies": { "@types/bun": "^1.2.8", "@typescript-eslint/eslint-plugin": "^8.29.0", "@typescript-eslint/parser": "^8.29.0", "eslint": "^9.24.0", "prettier": "^3.5.3" }, "peerDependencies": { "typescript": "^5.8.3" }, "dependencies": { "@better-auth/cli": "^1.2.5", "@better-auth/expo": "^1.2.5", "@types/cors": "^2.8.17", "@types/express": "^5.0.1", "@types/node": "^22.14.0", "better-auth": "^1.2.5", "better-sqlite3": "^11.9.1", "cors": "^2.8.5", "dotenv": "^16.4.7", "drizzle-kit": "^0.30.6", "drizzle-orm": "^0.41.0", "express": "^5.1.0", "helmet": "^8.1.0", "ts-node-dev": "^2.0.0", "zod": "^3.24.2" } } ```
GiteaMirror added the locked label 2026-04-13 04:22:02 -05:00
Author
Owner

@Kinfe123 commented on GitHub (Apr 7, 2025):

this is not from bun , better auth is not able to read your auth config file - despite having a default path for better auth to look for your auth config , you can pass your custom path for auth config with --config flag - bunx @better-auth/cli generate --config 'your-path-here'

<!-- gh-comment-id:2782115867 --> @Kinfe123 commented on GitHub (Apr 7, 2025): this is not from bun , better auth is not able to read your auth config file - despite having a default path for better auth to look for your auth config , you can pass your custom path for auth config with --config flag - `bunx @better-auth/cli generate --config 'your-path-here' `
Author
Owner

@Arsik0153 commented on GitHub (Apr 7, 2025):

@Kinfe123 My auth config is under ./src/utils/auth.ts folder. I'm trying like that:

bunx @better-auth/cli generate --config ./src/utils/auth.ts

It gives me the same error:

2025-04-07T17:10:45.924Z ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun:sqlite'

Probably should mention that when trying to use not existing path for config, it gives different error:

mymac@macbook % bunx @better-auth/cli generate --config "src/not-existing-path/auth.ts"
2025-04-07T17:18:24.780Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in /Users/***/src/utils/auth.ts. Make sure to default export your auth instance or to export as a variable named auth.

So I think error is indeed in bun:sqlite

<!-- gh-comment-id:2784041719 --> @Arsik0153 commented on GitHub (Apr 7, 2025): @Kinfe123 My auth config is under ./src/utils/auth.ts folder. I'm trying like that: ``` bunx @better-auth/cli generate --config ./src/utils/auth.ts ``` It gives me the same error: ``` 2025-04-07T17:10:45.924Z ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun:sqlite' ``` Probably should mention that when trying to use not existing path for config, it gives different error: ``` mymac@macbook % bunx @better-auth/cli generate --config "src/not-existing-path/auth.ts" 2025-04-07T17:18:24.780Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config in /Users/***/src/utils/auth.ts. Make sure to default export your auth instance or to export as a variable named auth. ``` So I think error is indeed in bun:sqlite
Author
Owner

@Kinfe123 commented on GitHub (Apr 7, 2025):

You should refer to your schema file not your auth config file ..which is your drizzle schema file for the output tho

<!-- gh-comment-id:2784317064 --> @Kinfe123 commented on GitHub (Apr 7, 2025): You should refer to your schema file not your auth config file ..which is your drizzle schema file for the output tho
Author
Owner

@Kinfe123 commented on GitHub (Apr 8, 2025):

This is actually for --output.

<!-- gh-comment-id:2785922876 --> @Kinfe123 commented on GitHub (Apr 8, 2025): This is actually for --output.
Author
Owner

@Kinfe123 commented on GitHub (Apr 8, 2025):

For the config it is your auth config ...

Is this still an issue ?

<!-- gh-comment-id:2785927893 --> @Kinfe123 commented on GitHub (Apr 8, 2025): For the config it is your auth config ... Is this still an issue ?
Author
Owner

@Arsik0153 commented on GitHub (Apr 8, 2025):

@Kinfe123 Yes, I am still confused. Here's my folder structure:

Image

auth.ts is my better-auth config file

So my cli should be bunx @better-auth/cli generate --config ./src/ right?
It is not working, getting the same error

<!-- gh-comment-id:2786122246 --> @Arsik0153 commented on GitHub (Apr 8, 2025): @Kinfe123 Yes, I am still confused. Here's my folder structure: <img width="241" alt="Image" src="https://github.com/user-attachments/assets/b532679a-338a-4e21-9f9a-f335dfac4a12" /> auth.ts is my better-auth config file So my cli should be ```bunx @better-auth/cli generate --config ./src/``` right? It is not working, getting the same error
Author
Owner

@Arsik0153 commented on GitHub (Apr 8, 2025):

After couple of tries, apparently I should use --bun argument to use cli properly with bun. So the final command would be:
bunx --bun @better-auth/cli generate --config ./src/auth.ts

This should be mentioned in docs probably

<!-- gh-comment-id:2786134927 --> @Arsik0153 commented on GitHub (Apr 8, 2025): After couple of tries, apparently I should use ```--bun``` argument to use cli properly with bun. So the final command would be: ```bunx --bun @better-auth/cli generate --config ./src/auth.ts``` This should be mentioned in docs probably
Author
Owner

@Kinfe123 commented on GitHub (Apr 8, 2025):

Yeah yeah it should be the case.

<!-- gh-comment-id:2786185839 --> @Kinfe123 commented on GitHub (Apr 8, 2025): Yeah yeah it should be the case.
Author
Owner

@bil0ak commented on GitHub (Jun 26, 2025):

After couple of tries, apparently I should use --bun argument to use cli properly with bun. So the final command would be: bunx --bun @better-auth/cli generate --config ./src/auth.ts

This should be mentioned in docs probably

THANK YOUUUUU

<!-- gh-comment-id:3007811695 --> @bil0ak commented on GitHub (Jun 26, 2025): > After couple of tries, apparently I should use `--bun` argument to use cli properly with bun. So the final command would be: `bunx --bun @better-auth/cli generate --config ./src/auth.ts` > > This should be mentioned in docs probably THANK YOUUUUU
Author
Owner

@auroradanier commented on GitHub (Aug 2, 2025):

i trie this command, still shows error

bunx --bun @better-auth/cli generate --config ./lib/auth.ts

[#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.

<!-- gh-comment-id:3146608298 --> @auroradanier commented on GitHub (Aug 2, 2025): i trie this command, still shows error bunx --bun @better-auth/cli generate --config ./lib/auth.ts [#better-auth]: Make sure to default export your auth instance or to export as a variable named auth.
Author
Owner

@marcospgp commented on GitHub (Aug 16, 2025):

I tried

bunx @better-auth/cli generate
# output:

node:internal/modules/esm/resolve:275
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/zod/dist/esm/v4/index.js' imported from /private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:275:11)
    at moduleResolve (node:internal/modules/esm/resolve:860:10)
    at defaultResolve (node:internal/modules/esm/resolve:984:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:137:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/zod/dist/esm/v4/index.js'
}

Node.js v22.16.0

and

bunx --bun @better-auth/cli generate
# output:

error: Cannot find module 'zod/v4' from '/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs'

Bun v1.2.19 (macOS arm64)

but both failed. In the end, this worked:

bunx npx @better-auth/cli generate

although I have no idea what bunx npx does behind the scenes

<!-- gh-comment-id:3193755504 --> @marcospgp commented on GitHub (Aug 16, 2025): I tried ``` bunx @better-auth/cli generate ``` ``` # output: node:internal/modules/esm/resolve:275 throw new ERR_MODULE_NOT_FOUND( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/zod/dist/esm/v4/index.js' imported from /private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs at finalizeResolution (node:internal/modules/esm/resolve:275:11) at moduleResolve (node:internal/modules/esm/resolve:860:10) at defaultResolve (node:internal/modules/esm/resolve:984:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:780:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:704:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:687:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:305:38) at ModuleJob._link (node:internal/modules/esm/module_job:137:49) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///private/tmp/bunx-501-@better-auth/cli@latest/node_modules/zod/dist/esm/v4/index.js' } Node.js v22.16.0 ``` and ``` bunx --bun @better-auth/cli generate ``` ``` # output: error: Cannot find module 'zod/v4' from '/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs' Bun v1.2.19 (macOS arm64) ``` but both failed. In the end, this worked: ``` bunx npx @better-auth/cli generate ``` although I have no idea what bunx npx does behind the scenes
Author
Owner

@marcospgp commented on GitHub (Aug 26, 2025):

@kaiqueaguilar bunx --bun @better-auth/cli generate results in the following output for me:

error: Cannot find module 'zod/v4' from '/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs'

Bun v1.2.21 (macOS arm64)

even after clearing cache with bun pm cache rm

<!-- gh-comment-id:3223613319 --> @marcospgp commented on GitHub (Aug 26, 2025): @kaiqueaguilar `bunx --bun @better-auth/cli generate` results in the following output for me: ``` error: Cannot find module 'zod/v4' from '/private/tmp/bunx-501-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs' Bun v1.2.21 (macOS arm64) ``` even after clearing cache with `bun pm cache rm`
Author
Owner

@candouss commented on GitHub (Aug 27, 2025):

even after clearing cache with bun pm cache rm

same here. error: Cannot find module 'zod/v4'

<!-- gh-comment-id:3226822163 --> @candouss commented on GitHub (Aug 27, 2025): > even after clearing cache with `bun pm cache rm` same here. `error: Cannot find module 'zod/v4' `
Author
Owner

@krisnaw commented on GitHub (Sep 2, 2025):

Hi @candouss, did you find the solution or a temporary workaround? I'm having similar issue 😬

<!-- gh-comment-id:3244410331 --> @krisnaw commented on GitHub (Sep 2, 2025): Hi @candouss, did you find the solution or a temporary workaround? I'm having similar issue 😬
Author
Owner

@MartinBspheroid commented on GitHub (Sep 3, 2025):

Same here. At least temporary workaround would be apretiated

<!-- gh-comment-id:3249283353 --> @MartinBspheroid commented on GitHub (Sep 3, 2025): Same here. At least temporary workaround would be apretiated
Author
Owner

@candouss commented on GitHub (Sep 3, 2025):

Hi @candouss, did you find the solution or a temporary workaround? I'm having similar issue 😬

@krisnaw, I couldn't find a proper solution exclusively in Bun, I had to install node and use npx conventionally.

<!-- gh-comment-id:3249733126 --> @candouss commented on GitHub (Sep 3, 2025): > Hi [@candouss](https://github.com/candouss), did you find the solution or a temporary workaround? I'm having similar issue 😬 @krisnaw, I couldn't find a proper solution exclusively in Bun, I had to install node and use npx conventionally.
Author
Owner

@marcospgp commented on GitHub (Sep 3, 2025):

the bun devs are tracking this issue: https://github.com/oven-sh/bun/issues/22184

<!-- gh-comment-id:3249876490 --> @marcospgp commented on GitHub (Sep 3, 2025): the bun devs are tracking this issue: https://github.com/oven-sh/bun/issues/22184
Author
Owner

@krisnaw commented on GitHub (Sep 3, 2025):

Hi @candouss, thanks for the response. I found the solution, I need to install the Better-Auth CLI separately to make it work. My project setup is Hono.js + Bun.

<!-- gh-comment-id:3251114397 --> @krisnaw commented on GitHub (Sep 3, 2025): Hi @candouss, thanks for the response. I found the solution, I need to install the Better-Auth CLI separately to make it work. My project setup is Hono.js + Bun.
Author
Owner

@saddansyah commented on GitHub (Sep 9, 2025):

After couple of tries, apparently I should use --bun argument to use cli properly with bun. So the final command would be: bunx --bun @better-auth/cli generate --config ./src/auth.ts

This should be mentioned in docs probably

BIG THANKS BROTHER

<!-- gh-comment-id:3270020700 --> @saddansyah commented on GitHub (Sep 9, 2025): > After couple of tries, apparently I should use `--bun` argument to use cli properly with bun. So the final command would be: `bunx --bun @better-auth/cli generate --config ./src/auth.ts` > > This should be mentioned in docs probably BIG THANKS BROTHER
Author
Owner

@nielpattin commented on GitHub (Oct 10, 2025):

Hi @candouss, thanks for the response. I found the solution, I need to install the Better-Auth CLI separately to make it work. My project setup is Hono.js + Bun.

Thank you!

<!-- gh-comment-id:3388211018 --> @nielpattin commented on GitHub (Oct 10, 2025): > Hi [@candouss](https://github.com/candouss), thanks for the response. I found the solution, I need to install the Better-Auth CLI separately to make it work. My project setup is Hono.js + Bun. Thank you!
Author
Owner

@zeekrey commented on GitHub (Oct 16, 2025):

I tried a bunch of solutions with Bun SQL, but I just couldn't get it to work.

Using Bun SQL

//auth.ts
import { betterAuth } from 'better-auth'
import { SQL } from 'bun'

export const auth = betterAuth({
  database: new SQL('sqlite://auth.db'),
  emailAndPassword: {
    enabled: true,
  },
})
npx @better-auth/cli generate
-> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun'
bunx npx @better-auth/cli generate --config ./src/lib/auth.ts
-> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun'
bunx --bun @better-auth/cli generate --config ./src/lib/auth.ts
TypeError: undefined is not a constructor (evaluating 'new _bun.SQL('sqlite://auth.db')')

better-sqlite3

//auth.ts
import { betterAuth } from 'better-auth'
import Database from 'better-sqlite3'

export const auth = betterAuth({
  database: new Database('./data/auth.db'),
  emailAndPassword: {
    enabled: true,
  },
})

and

npx @better-auth/cli generate and it worked.

<!-- gh-comment-id:3408918686 --> @zeekrey commented on GitHub (Oct 16, 2025): I tried a bunch of solutions with Bun SQL, but I just couldn't get it to work. **Using Bun SQL** ```typescript //auth.ts import { betterAuth } from 'better-auth' import { SQL } from 'bun' export const auth = betterAuth({ database: new SQL('sqlite://auth.db'), emailAndPassword: { enabled: true, }, }) ``` ``` npx @better-auth/cli generate -> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun' ``` ``` bunx npx @better-auth/cli generate --config ./src/lib/auth.ts -> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun' ``` ``` bunx --bun @better-auth/cli generate --config ./src/lib/auth.ts TypeError: undefined is not a constructor (evaluating 'new _bun.SQL('sqlite://auth.db')') ``` **better-sqlite3** ```typescript //auth.ts import { betterAuth } from 'better-auth' import Database from 'better-sqlite3' export const auth = betterAuth({ database: new Database('./data/auth.db'), emailAndPassword: { enabled: true, }, }) ``` and `npx @better-auth/cli generate` and it worked.
Author
Owner

@Hyuuh commented on GitHub (Feb 22, 2026):

I tried a bunch of solutions with Bun SQL, but I just couldn't get it to work.

Using Bun SQL

//auth.ts
import { betterAuth } from 'better-auth'
import { SQL } from 'bun'

export const auth = betterAuth({
database: new SQL('sqlite://auth.db'),
emailAndPassword: {
enabled: true,
},
})

npx @better-auth/cli generate
-> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun'
bunx npx @better-auth/cli generate --config ./src/lib/auth.ts
-> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun'
bunx --bun @better-auth/cli generate --config ./src/lib/auth.ts
TypeError: undefined is not a constructor (evaluating 'new _bun.SQL('sqlite://auth.db')')

better-sqlite3

//auth.ts
import { betterAuth } from 'better-auth'
import Database from 'better-sqlite3'

export const auth = betterAuth({
database: new Database('./data/auth.db'),
emailAndPassword: {
enabled: true,
},
})
and

npx @better-auth/cli generate and it worked.

In bun, you need to use --bun, so: bunx --bun @better-auth/cli generate

<!-- gh-comment-id:3941870292 --> @Hyuuh commented on GitHub (Feb 22, 2026): > I tried a bunch of solutions with Bun SQL, but I just couldn't get it to work. > > **Using Bun SQL** > > //auth.ts > import { betterAuth } from 'better-auth' > import { SQL } from 'bun' > > export const auth = betterAuth({ > database: new SQL('sqlite://auth.db'), > emailAndPassword: { > enabled: true, > }, > }) > ``` > npx @better-auth/cli generate > -> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun' > ``` > > ``` > bunx npx @better-auth/cli generate --config ./src/lib/auth.ts > -> ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun' > ``` > > ``` > bunx --bun @better-auth/cli generate --config ./src/lib/auth.ts > TypeError: undefined is not a constructor (evaluating 'new _bun.SQL('sqlite://auth.db')') > ``` > > **better-sqlite3** > > //auth.ts > import { betterAuth } from 'better-auth' > import Database from 'better-sqlite3' > > export const auth = betterAuth({ > database: new Database('./data/auth.db'), > emailAndPassword: { > enabled: true, > }, > }) > and > > `npx @better-auth/cli generate` and it worked. In bun, you need to use `--bun`, so: `bunx --bun @better-auth/cli generate`
Author
Owner

@devguilhermy commented on GitHub (Mar 19, 2026):

The command seems to have been updated.
You now gotta run bunx --bun auth@latest generate instead. (Drop the better-)

<!-- gh-comment-id:4090470626 --> @devguilhermy commented on GitHub (Mar 19, 2026): The command seems to have been updated. You now gotta run `bunx --bun auth@latest generate` instead. (Drop the `better-`)
Author
Owner

@github-actions[bot] commented on GitHub (Mar 31, 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:4165913354 --> @github-actions[bot] commented on GitHub (Mar 31, 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#9071