Bun on Docker fails due to Better-Auth using better-sqlite3 #2876

Closed
opened 2026-03-13 10:25:06 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @JaviZamudio on GitHub (Feb 16, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Have a NextJs project, with Prisma using Mongodb
  2. Add better-auth as a dependency
  3. Try to run your Dockerfile (image: "oven/bun:1", step: "bun install")

Current vs. Expected behavior

I would expect it to run perfectly, as it did before, but...

Current:
It installs a whole ton amount of unnecessary deps, like drizzle, svelte, sqlite, mysql

Among them, even if i dont use it: better-sqlite3, which takes unnecessary space, but also breaks the installation

What version of Better Auth are you using?

1.4.18 (yes, i tried 1.3.27 too)

System info

Dockerfile
FROM oven/bun:1 AS builder
WORKDIR /app

COPY bun.lock package*.json ./
RUN bun install
... <more steps> ...

package.json
... <prev code> ...

"better-auth": "1.3.27",
... <more code ...


And in the install step, it says:
 > [builder 4/7] RUN bun install:
4.923 bun install v1.3.9 (cf6cdbbb)
243.8 prebuild-install warn install 'better-sqlite3' is not yet supported in Bun.
243.8 Track the status in https://github.com/oven-sh/bun/issues/4290
243.8 In the meantime, you could try bun:sqlite which has a similar API.
...... <more logs> ......
243.8 error: install script from "better-sqlite3" exited with 1
------
Dockerfile:8
--------------------
   6 |     
   7 |     COPY bun.lock package*.json ./
   8 | >>> RUN bun install
   9 |     
  10 |     COPY . .
--------------------

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

Package

Auth config (if applicable)

export const auth = betterAuth({
    secret: AUTH_SECRET,
    baseURL: AUTH_URL,
    database: prismaAdapter(prisma, {
        provider: "mongodb",
    }),
    emailAndPassword: {
        enabled: true,
        autoSignIn: true,
    },
    advanced: {
        database: {
            generateId: false,
        },
    },
    plugins: [
        nextCookies(),
    ],
});

Additional context

I've seen similar issues, and you suggest a multi-stage build, but installing a whole new image just to build a package not used at all?
Also you suggested an earlier version and it didn't work either.

Is there a modular way to add or remove database managers? (and even other frameworks, like vite, svelte kit, etc)... why add them all?

Or is there an official workaround to do this? cause you even give bun as an install option as if bun was supported... like "you can remove this dep like: X"

Or a Bun guide? "You need first to do X, then add: Y, and build like: Z"

I've been trying to work this out for a while and each build takes for ever and still fails, Thanks!

Originally created by @JaviZamudio on GitHub (Feb 16, 2026). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Have a NextJs project, with Prisma using Mongodb 2. Add better-auth as a dependency 3. Try to run your Dockerfile (image: "oven/bun:1", step: "bun install") ### Current vs. Expected behavior I would expect it to run perfectly, as it did before, but... Current: It installs a whole ton amount of unnecessary deps, like drizzle, svelte, sqlite, mysql Among them, even if i dont use it: *better-sqlite3*, which takes unnecessary space, but also breaks the installation ### What version of Better Auth are you using? 1.4.18 (yes, i tried 1.3.27 too) ### System info ```bash Dockerfile FROM oven/bun:1 AS builder WORKDIR /app COPY bun.lock package*.json ./ RUN bun install ... <more steps> ... package.json ... <prev code> ... "better-auth": "1.3.27", ... <more code ... And in the install step, it says: > [builder 4/7] RUN bun install: 4.923 bun install v1.3.9 (cf6cdbbb) 243.8 prebuild-install warn install 'better-sqlite3' is not yet supported in Bun. 243.8 Track the status in https://github.com/oven-sh/bun/issues/4290 243.8 In the meantime, you could try bun:sqlite which has a similar API. ...... <more logs> ...... 243.8 error: install script from "better-sqlite3" exited with 1 ------ Dockerfile:8 -------------------- 6 | 7 | COPY bun.lock package*.json ./ 8 | >>> RUN bun install 9 | 10 | COPY . . -------------------- ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript export const auth = betterAuth({ secret: AUTH_SECRET, baseURL: AUTH_URL, database: prismaAdapter(prisma, { provider: "mongodb", }), emailAndPassword: { enabled: true, autoSignIn: true, }, advanced: { database: { generateId: false, }, }, plugins: [ nextCookies(), ], }); ``` ### Additional context I've seen similar issues, and you suggest a multi-stage build, but installing a whole new image just to build a package not used at all? Also you suggested an earlier version and it didn't work either. Is there a modular way to add or remove database managers? (and even other frameworks, like vite, svelte kit, etc)... why add them all? Or is there an official workaround to do this? cause you even give bun as an install option as if bun was supported... like "you can remove this dep like: X" Or a Bun guide? "You need first to do X, then add: Y, and build like: Z" I've been trying to work this out for a while and each build takes for ever and still fails, Thanks!
GiteaMirror added the bug label 2026-03-13 10:25:06 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Feb 16, 2026):

Hi @JaviZamudio! I'm Dosu and I’m helping the better-auth team.

This is a known issue with Bun + Docker and better-sqlite3. The problem is that better-sqlite3 requires native compilation (node-gyp, Python, build tools), which Bun doesn't fully support.

Why better-sqlite3 is being installed: If you have @better-auth/cli as a dependency (even as a devDependency), it brings in better-sqlite3 as a transitive dependency. This was recently fixed in PR #7771 which moved it to devDependencies in the CLI package.

Workarounds:

  1. Use --production flag: Run bun install --production to skip devDependencies and avoid installing the CLI's transitive deps in your Docker build.

  2. Multi-stage build with build tools:

FROM oven/bun:1 AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y python3 build-essential

COPY bun.lock package*.json ./
RUN bun install

FROM oven/bun:1-slim
WORKDIR /app
COPY --from=builder /app/node_modules ./node_modules
COPY . .
  1. Use pnpm for installation: pnpm handles optional dependencies more intelligently and is consistently recommended for this issue. You can use pnpm just for installation and still run with Bun.

  2. Upgrade to latest: Better Auth 1.4+ includes the CLI fix, and recent versions have separated adapters into standalone packages for better tree-shaking.

For your use case with Prisma + MongoDB, the --production flag is likely the quickest fix if you're using the CLI only during development.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Feb 16, 2026): <!-- Greeting --> Hi @JaviZamudio! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue with Bun + Docker and better-sqlite3. The problem is that better-sqlite3 requires native compilation (node-gyp, Python, build tools), which Bun doesn't fully support. **Why better-sqlite3 is being installed**: If you have `@better-auth/cli` as a dependency (even as a devDependency), it [brings in better-sqlite3 as a transitive dependency](https://github.com/better-auth/better-auth/issues/7761#issuecomment-3834981045). This was [recently fixed in PR #7771](https://github.com/better-auth/better-auth/pull/7771) which moved it to devDependencies in the CLI package. **Workarounds**: 1. **Use `--production` flag**: Run `bun install --production` to skip devDependencies and avoid installing the CLI's transitive deps in your Docker build. 2. **Multi-stage build with build tools**: ```dockerfile FROM oven/bun:1 AS builder WORKDIR /app RUN apt-get update && apt-get install -y python3 build-essential COPY bun.lock package*.json ./ RUN bun install FROM oven/bun:1-slim WORKDIR /app COPY --from=builder /app/node_modules ./node_modules COPY . . ``` 3. **Use pnpm for installation**: pnpm [handles optional dependencies more intelligently](https://github.com/better-auth/better-auth/issues/4305#issuecomment-3237534368) and is consistently recommended for this issue. You can use pnpm just for installation and still run with Bun. 4. **Upgrade to latest**: Better Auth 1.4+ includes the [CLI fix](https://github.com/better-auth/better-auth/pull/7771), and recent versions have [separated adapters into standalone packages](https://github.com/better-auth/better-auth/pull/7439) for better tree-shaking. For your use case with Prisma + MongoDB, the `--production` flag is likely the quickest fix if you're using the CLI only during development. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/3ca2905c-8c30-4a70-b79b-30e3cb21840e?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue%20with%20Bun%20%2B%20Docker%20and%20better-sqlite3.%20The%20problem%20is%20that%20better-sqlite3%20requires%20native%20compilation%20%28node-gyp%2C%20Python%2C%20build%20tools%29%2C%20which%20Bun%20doesn%27t%20fully%20support.%0A%0A%2A%2AWhy%20better-sqlite3%20is%20being%20installed%2A%2A%3A%20If%20you%20have%20%60%40better-auth/cli%60%20as%20a%20dependency%20%28even%20as%20a%20devDependency%29%2C%20it%20%5Bbrings%20in%20better-sqlite3%20as%20a%20transitive%20dependency%5D%28https%3A//github.com/better-auth/better-auth/issues/7761%23issuecomment-3834981045%29.%20This%20was%20%5Brecently%20fixed%20in%20PR%20%237771%5D%28https%3A//github.com/better-auth/better-auth/pull/7771%29%20which%20moved%20it%20to%20devDependencies%20in%20the%20CLI%20package.%0A%0A%2A%2AWorkarounds%2A%2A%3A%0A%0A1.%20%2A%2AUse%20%60--production%60%20flag%2A%2A%3A%20Run%20%60bun%20install%20--production%60%20to%20skip%20devDependencies%20and%20avoid%20installing%20the%20CLI%27s%20transitive%20deps%20in%20your%20Docker%20build.%0A%0A2.%20%2A%2AMulti-stage%20build%20with%20build%20tools%2A%2A%3A%0A%60%60%60dockerfile%0AFROM%20oven/bun%3A1%20AS%20builder%0AWORKDIR%20/app%0ARUN%20apt-get%20update%20%26%26%20apt-get%20install%20-y%20python3%20build-essential%0A%0ACOPY%20bun.lock%20package%2A.json%20./%0ARUN%20bun%20install%0A%0AFROM%20oven/bun%3A1-slim%0AWORKDIR%20/app%0ACOPY%20--from%3Dbuilder%20/app/node_modules%20./node_modules%0ACOPY%20.%20.%0A%60%60%60%0A%0A3.%20%2A%2AUse%20pnpm%20for%20installation%2A%2A%3A%20pnpm%20%5Bhandles%20optional%20dependencies%20more%20intelligently%5D%28https%3A//github.com/better-auth/better-auth/issues/4305%23issuecomment-3237534368%29%20and%20is%20consistently%20recommended%20for%20this%20issue.%20You%20can%20use%20pnpm%20just%20for%20installation%20and%20still%20run%20with%20Bun.%0A%0A4.%20%2A%2AUpgrade%20to%20latest%2A%2A%3A%20Better%20Auth%201.4%2B%20includes%20the%20%5BCLI%20fix%5D%28https%3A//github.com/better-auth/better-auth/pull/7771%29%2C%20and%20recent%20versions%20have%20%5Bseparated%20adapters%20into%20standalone%20packages%5D%28https%3A//github.com/better-auth/better-auth/pull/7439%29%20for%20better%20tree-shaking.%0A%0AFor%20your%20use%20case%20with%20Prisma%20%2B%20MongoDB%2C%20the%20%60--production%60%20flag%20is%20likely%20the%20quickest%20fix%20if%20you%27re%20using%20the%20CLI%20only%20during%20development.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/7987)
Author
Owner

@JaviZamudio commented on GitHub (Feb 16, 2026):

I don't know why, but after like 3 hours of trying, I just had to erase the .lock file :(

@JaviZamudio commented on GitHub (Feb 16, 2026): I don't know why, but after like 3 hours of trying, I just had to erase the .lock file :(
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2876