Betterauth CLI Fails on sqlite

https://www.better-auth.com/docs/adapters/sqlite After following guide from docs, Cannot generate using see error messages.
SQLite | Better Auth
Integrate Better Auth with SQLite.
11 Replies
lonelyplanet
lonelyplanetOP3w ago
Auth.ts
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";

export const auth = betterAuth({
database: new Database("database.sqlite"),
});
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";

export const auth = betterAuth({
database: new Database("database.sqlite"),
});
Installed better-auth,better-sqlite3 and @types/better-sqlite3 Is there a different way to start with sqlite than following the guide, if not can the docs be looked at
lonelyplanet
lonelyplanetOP3w ago
And issue with similar issues is still open since december 2024, Surely by now this issue would of been documented or fixed: https://github.com/better-auth/better-auth/issues/892
GitHub
Using @better-auth/cli generate with Sqlite & Bun / Deno fails wi...
Is this suited for github? Yes, this is suited for github To Reproduce Follow "Getting started" guide on docs. (using Next.js) Create config in lib/auth.ts import { betterAuth } from &quo...
lonelyplanet
lonelyplanetOP3w ago
@bekacru what is the proper way to initalize a sqlite betterauth project and generate using the CLI and pnpm?
Ping
Ping3w ago
@lonelyplanet Do you know if running migrate will work? I often use better-sqlite3 to do testing and stuff and it works fine, but I only use migrate.
bekacru
bekacru3w ago
for Bun you need to use a kysley dialect. Better Auth only support better-sqlite3 out of the box
lonelyplanet
lonelyplanetOP3w ago
Not bun.
bekacru
bekacru3w ago
hmm? so it's not working with better-sqlite3?
lonelyplanet
lonelyplanetOP3w ago
yes
bekacru
bekacru3w ago
oh this has something to do with better-sqlite3 binary jsut try to use better-sqlite alone and see if it works
SyntaxErrorGeek
I have the same issue.
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";

export const auth = betterAuth({
database: new Database("./sqlite.db"),
emailAndPassword: {
enabled: true,
},
socialProviders: {
microsoft: {
clientId: process.env.MICROSOFT_CLIENT_ID || "",
clientSecret: process.env.MICROSOFT_CLIENT_SECRET || "",
tenantId: process.env.MICROSOFT_TENANT_ID,
disableProfilePhoto: true,
},
},
});
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";

export const auth = betterAuth({
database: new Database("./sqlite.db"),
emailAndPassword: {
enabled: true,
},
socialProviders: {
microsoft: {
clientId: process.env.MICROSOFT_CLIENT_ID || "",
clientSecret: process.env.MICROSOFT_CLIENT_SECRET || "",
tenantId: process.env.MICROSOFT_TENANT_ID,
disableProfilePhoto: true,
},
},
});
Running pnpm dlx @better-auth/cli migrate gives the attached error.
SyntaxErrorGeek
Tried better-sqlite3 versions 11.x, 10.x, 9.x and get the same error. Also tested with node-sqlite3 with same error. I think this is a better-auth cli bug I belive I found the solution. After installing better-sqlite3 you need to approve it to run build scripts. For me using PNPM runpnpm approve-builds and then select better-sqlite3. Then you can run the CLI command.

Did you find this page helpful?