[GH-ISSUE #892] Using @better-auth/cli generate with Sqlite & Bun / Deno fails with "Could not locate the bindings file." #17117

Closed
opened 2026-04-15 15:04:02 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @skoshx on GitHub (Dec 14, 2024).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/892

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Follow "Getting started" guide on docs. (using Next.js)
  2. Create config in lib/auth.ts
import { betterAuth } from "better-auth";
import Database from "better-sqlite3";
import { SQLITE_DATABASE_PATH } from "./sql";
 
export const auth = betterAuth({
  database: new Database(SQLITE_DATABASE_PATH),
})
  1. Run bunx @better-auth/cli generate
  2. Error presents:
bunx @better-auth/cli generate

[Better Auth]  ERROR   [#better-auth]: Error: Could not locate the bindings file. Tried:
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Release/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/Debug/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Release/better_sqlite3.node

Current vs. Expected behavior

bunx @better-auth/cli generate

[Better Auth]  ERROR   [#better-auth]: Error: Could not locate the bindings file. Tried:
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Debug/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Release/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Debug/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/Debug/better_sqlite3.node
 → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Release/better_sqlite3.node

What version of Better Auth are you using?

"better-auth": "^1.0.20",

Provide environment information

- Bun version 1.0.11
- deno 2.1.3 (stable, release, aarch64-apple-darwin)
v8 13.0.245.12-rusty
typescript 5.6.2

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

Other

Auth config (if applicable)

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

Additional context

Works just fine with pnpm. Must be some weird quirk.

Originally created by @skoshx on GitHub (Dec 14, 2024). Original GitHub issue: https://github.com/better-auth/better-auth/issues/892 ### Is this suited for github? - [X] Yes, this is suited for github ### To Reproduce 1. Follow "Getting started" guide on docs. (using Next.js) 2. Create config in `lib/auth.ts` ```typescript import { betterAuth } from "better-auth"; import Database from "better-sqlite3"; import { SQLITE_DATABASE_PATH } from "./sql"; export const auth = betterAuth({ database: new Database(SQLITE_DATABASE_PATH), }) ``` 3. Run `bunx @better-auth/cli generate` 4. Error presents: ``` bunx @better-auth/cli generate [Better Auth] ERROR [#better-auth]: Error: Could not locate the bindings file. Tried: → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Debug/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Release/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Debug/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/Debug/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Release/better_sqlite3.node ``` ### Current vs. Expected behavior ``` bunx @better-auth/cli generate [Better Auth] ERROR [#better-auth]: Error: Could not locate the bindings file. Tried: → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Debug/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/build/Release/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Debug/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/Debug/better_sqlite3.node → /Desktop/DEV/Web/test-proj/node_modules/better-sqlite3/out/Release/better_sqlite3.node ``` ### What version of Better Auth are you using? "better-auth": "^1.0.20", ### Provide environment information ```bash - Bun version 1.0.11 - deno 2.1.3 (stable, release, aarch64-apple-darwin) v8 13.0.245.12-rusty typescript 5.6.2 ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import Database from "better-sqlite3"; import { SQLITE_DATABASE_PATH } from "./sql"; export const auth = betterAuth({ database: new Database(SQLITE_DATABASE_PATH), }) ``` ### Additional context Works just fine with `pnpm`. Must be some weird quirk.
GiteaMirror added the lockedbug labels 2026-04-15 15:04:02 -05:00
Author
Owner

@Bekacru commented on GitHub (Dec 16, 2024):

I think this has something to do with bun compatibility with better-sqlite3 instead

<!-- gh-comment-id:2544638100 --> @Bekacru commented on GitHub (Dec 16, 2024): I think this has something to do with bun compatibility with `better-sqlite3` instead
Author
Owner

@skoshx commented on GitHub (Dec 16, 2024):

Also doesn't work with Deno. I understand that this is one of those issues that should instead be properly resolved on better-sqlite3 repo, however, I think it would be useful to at the very least add some "Warning / Troubleshooting" notice in the docs that says something like "If you want to use Sqlite with Deno or Bun, use "

I think it's really important that the "Getting started" flow works for most cases, and I don't think that Bun / Deno is that niche anymore these days :D

<!-- gh-comment-id:2545044447 --> @skoshx commented on GitHub (Dec 16, 2024): Also doesn't work with Deno. I understand that this is one of those issues that should instead be properly resolved on `better-sqlite3` repo, however, I think it would be useful to at the very least add some "Warning / Troubleshooting" notice in the docs that says something like "If you want to use Sqlite with Deno or Bun, use <package that works>" I think it's really important that the "Getting started" flow works for most cases, and I don't think that Bun / Deno is that niche anymore these days :D
Author
Owner

@shepherdjerred commented on GitHub (Dec 17, 2024):

I was able to get around this by running:

# make the better-auth cli happy
npm i better-auth better-sqlite3
# run the cli
npx @better-auth/cli generate
# remove unneeded node stuff
rm -rfv package.json package-lock.json node_modules

After the database is generated I don't see why you'd need the CLI again, so you can just purge everything.

<!-- gh-comment-id:2547481761 --> @shepherdjerred commented on GitHub (Dec 17, 2024): I was able to get around this by running: ``` # make the better-auth cli happy npm i better-auth better-sqlite3 # run the cli npx @better-auth/cli generate # remove unneeded node stuff rm -rfv package.json package-lock.json node_modules ``` After the database is generated I don't see why you'd need the CLI again, so you can just purge everything.
Author
Owner

@chandy commented on GitHub (Feb 8, 2025):

I had the same issue as @skoshx . I was able to replicate it using npm and pnpm. The main issue was that the install was not creating a build directory while running. You can look in your node_modules folder under the better-sqlite3 folder and see this. I was able to get around this using npm rebuild better-sqlite3 for npm. For pnpm that command will ignore the build unless you approve it. So you can run pnpm approve-builds after you install it to approve the building for better-sqlite3. I can not speak to bun but I assume there might me something similar happening there where it won't build fully unless told to do so explicitly. Hope this helps

<!-- gh-comment-id:2645888544 --> @chandy commented on GitHub (Feb 8, 2025): I had the same issue as @skoshx . I was able to replicate it using npm and pnpm. The main issue was that the install was not creating a build directory while running. You can look in your node_modules folder under the better-sqlite3 folder and see this. I was able to get around this using `npm rebuild better-sqlite3` for npm. For pnpm that command will ignore the build unless you approve it. So you can run `pnpm approve-builds` after you install it to approve the building for better-sqlite3. I can not speak to bun but I assume there might me something similar happening there where it won't build fully unless told to do so explicitly. Hope this helps
Author
Owner

@benhovinga commented on GitHub (Mar 28, 2025):

@chandy thanks this worked. I just had to run pnpm approve-builds and select better-sqlite3. The CLI commands now work.

<!-- gh-comment-id:2761541598 --> @benhovinga commented on GitHub (Mar 28, 2025): @chandy thanks this worked. I just had to run `pnpm approve-builds` and select better-sqlite3. The CLI commands now work.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#17117