CLI failing to generate Drizzle schema with Postgres #1808

Closed
opened 2026-03-13 09:04:57 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @Cosina14 on GitHub (Aug 29, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

This is a vanilla setup

  1. npx create-next-app@latest
  2. npm install drizzle-orm
  3. npm install drizzle-kit --save-dev
  4. npm install @neondatabase/serverless
  5. npm install better-auth
  6. Setup .env in root and auth.ts in /lib (auth.ts is vanilla and based on https://www.better-auth.com/docs/installation)
  7. Setup Drizzle stuff vanilla as per https://orm.drizzle.team/docs/tutorials/drizzle-nextjs-neon
  8. sudo apt install build-essential
  9. npm install -g node-gyp
  10. npx --verbose @better-auth/cli generate

Step 10 will fail which led me to come up with Steps 8 and 9 but it didnt help

os= Linux 6.6.87.2-microsoft-standard-WSL2
node= v24.7.0
npm= v11.5.2

Seems to fail at =>

npm http cache semver@https://registry.npmjs.org/semver/-/semver-6.3.1.tgz 0ms (cache hit)
npm http cache dotenv@https://registry.npmjs.org/dotenv/-/dotenv-17.2.1.tgz 0ms (cache hit)
npm http cache semver@https://registry.npmjs.org/semver/-/semver-6.3.1.tgz 0ms (cache hit)
npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 710ms
npm info run prisma@5.22.0 preinstall node_modules/prisma node scripts/preinstall-entry.js
npm info run prisma@5.22.0 preinstall { code: 0, signal: null }
npm info run better-sqlite3@11.10.0 install node_modules/better-sqlite3 prebuild-install || node-gyp rebuild --release
npm info run better-sqlite3@11.10.0 install { code: 1, signal: null }

Works with pnpm however. Go figure!
I also wonder why its trying to get things like better-sqlite3 when postgres is required or prisma when drizzle is being used.

Current vs. Expected behavior

Expect auth-schema.ts to generate but CLI is failing

What version of Better Auth are you using?

1.3.7

System info

OS: Linux 6.6 Ubuntu 25.04 25.04 (Plucky Puffin)
CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-1235U
Memory: 1.13 GB / 3.66 GB
Container: Yes
Shell: 5.2.37 - /bin/bash

node= v24.7.0
npm=  v11.5.2

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

Other

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { db } from "@/db/drizzle";
 
export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "pg",
    }),
});

Additional context

No response

Originally created by @Cosina14 on GitHub (Aug 29, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce This is a vanilla setup 1. npx create-next-app@latest 2. npm install drizzle-orm 3. npm install drizzle-kit --save-dev 4. npm install @neondatabase/serverless 5. npm install better-auth 6. Setup .env in root and auth.ts in /lib (auth.ts is vanilla and based on https://www.better-auth.com/docs/installation) 7. Setup Drizzle stuff vanilla as per https://orm.drizzle.team/docs/tutorials/drizzle-nextjs-neon 8. sudo apt install build-essential 9. npm install -g node-gyp 10. npx --verbose @better-auth/cli generate Step 10 will fail which led me to come up with Steps 8 and 9 but it didnt help os= Linux 6.6.87.2-microsoft-standard-WSL2 node= v24.7.0 npm= v11.5.2 Seems to fail at => npm http cache semver@https://registry.npmjs.org/semver/-/semver-6.3.1.tgz 0ms (cache hit) npm http cache dotenv@https://registry.npmjs.org/dotenv/-/dotenv-17.2.1.tgz 0ms (cache hit) npm http cache semver@https://registry.npmjs.org/semver/-/semver-6.3.1.tgz 0ms (cache hit) npm http fetch POST 200 https://registry.npmjs.org/-/npm/v1/security/advisories/bulk 710ms npm info run prisma@5.22.0 preinstall node_modules/prisma node scripts/preinstall-entry.js npm info run prisma@5.22.0 preinstall { code: 0, signal: null } npm info run better-sqlite3@11.10.0 install node_modules/better-sqlite3 prebuild-install || node-gyp rebuild --release npm info run better-sqlite3@11.10.0 install { code: 1, signal: null } Works with pnpm however. Go figure! I also wonder why its trying to get things like better-sqlite3 when postgres is required or prisma when drizzle is being used. ### Current vs. Expected behavior Expect auth-schema.ts to generate but CLI is failing ### What version of Better Auth are you using? 1.3.7 ### System info ```bash OS: Linux 6.6 Ubuntu 25.04 25.04 (Plucky Puffin) CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-1235U Memory: 1.13 GB / 3.66 GB Container: Yes Shell: 5.2.37 - /bin/bash node= v24.7.0 npm= v11.5.2 ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/db/drizzle"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), }); ``` ### Additional context _No response_
GiteaMirror added the nextjsbug labels 2026-03-13 09:04:57 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 29, 2025):

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

The CLI is trying to install better-sqlite3 and prisma because they are listed as direct dependencies in the Better Auth CLI’s package.json, not because your config or adapter requires them. npm installs all dependencies listed, even if you’re only using Drizzle with Postgres. pnpm, on the other hand, handles dependency hoisting differently and may avoid installing unnecessary packages if they’re not required by your code path, which is why the CLI works with pnpm but fails with npm in your setup.

There’s no logic in the CLI or adapter code to conditionally install or require these dependencies based on your database provider—they’re always installed if you use npm, which can cause failures if your environment can’t build native modules like better-sqlite3 (source).

Workarounds: use pnpm instead of npm, or manually patch/remove unnecessary dependencies from your local CLI package.json if you must use npm. There’s currently no config or documented way to avoid these dependencies for non-SQLite/Prisma setups.

This is a known pain point and has come up in other contexts (like Cloudflare D1 and Drizzle/Postgres). Improving dependency management in the CLI would help avoid these issues (source).

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Aug 29, 2025): <!-- Greeting --> Hi @Cosina14! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The CLI is trying to install better-sqlite3 and prisma because they are listed as direct dependencies in the Better Auth CLI’s package.json, not because your config or adapter requires them. npm installs all dependencies listed, even if you’re only using Drizzle with Postgres. pnpm, on the other hand, handles dependency hoisting differently and may avoid installing unnecessary packages if they’re not required by your code path, which is why the CLI works with pnpm but fails with npm in your setup. There’s no logic in the CLI or adapter code to conditionally install or require these dependencies based on your database provider—they’re always installed if you use npm, which can cause failures if your environment can’t build native modules like better-sqlite3 [(source)](https://github.com/better-auth/better-auth/blob/6083855a5377e3e0dbb25b4ce915eaf35ce25ed2/packages/cli/package.json). Workarounds: use pnpm instead of npm, or manually patch/remove unnecessary dependencies from your local CLI package.json if you must use npm. There’s currently no config or documented way to avoid these dependencies for non-SQLite/Prisma setups. This is a known pain point and has come up in other contexts (like Cloudflare D1 and Drizzle/Postgres). Improving dependency management in the CLI would help avoid these issues [(source)](https://github.com/better-auth/better-auth/issues/3549). <!-- 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/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/0e753c43-9226-4c5d-962a-714936f7128c?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/4305)
Author
Owner

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

better-sqlite3 is used primary for inference of some db interface. and vanilla sqlite connection and can you please show your current config looks like for auth and db just to check if it is pkg rebuild issue ?

@Kinfe123 commented on GitHub (Sep 2, 2025): better-sqlite3 is used primary for inference of some db interface. and vanilla sqlite connection and can you please show your current config looks like for auth and db just to check if it is pkg rebuild issue ?
Author
Owner

@Kinfe123 commented on GitHub (Sep 5, 2025):

closing due to no response. let me if this issue still persists and you think it is from better-auth.

@Kinfe123 commented on GitHub (Sep 5, 2025): closing due to no response. let me if this issue still persists and you think it is from better-auth.
Author
Owner

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

Apologies for delay
Tough for me to say if its from better-auth.
I can confirm it works with pnpm but not npm. E
ven if this is not from better-auth it may be worth investigating and documenting as npm is fairly popular and the default/first practice in the better-auth docs?

When running CLI in verbose, the issue happens at

npm info run better-sqlite3@11.10.0 install node_modules/better-sqlite3 prebuild-install || node-gyp rebuild --release
npm info run better-sqlite3@11.10.0 install { code: 1, signal: null }

auth.js //Vanilla straight out of https://www.better-auth.com/docs/installation

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

export const auth = betterAuth({
database: drizzleAdapter(db, {
provider: "pg",
}),
});

db.js //Vanilla straight out of https://orm.drizzle.team/docs/tutorials/drizzle-with-neon

import { drizzle } from "drizzle-orm/neon-http";
import { neon } from "@neondatabase/serverless";
import { config } from "dotenv";
config({ path: ".env" }); // or .env.local
const sql = neon(process.env.DATABASE_URL!);
export const db = drizzle({ client: sql });

@Cosina14 commented on GitHub (Sep 9, 2025): Apologies for delay Tough for me to say if its from better-auth. I can confirm it works with pnpm but not npm. E ven if this is not from better-auth it may be worth investigating and documenting as npm is fairly popular and the default/first practice in the better-auth docs? When running CLI in verbose, the issue happens at npm info run better-sqlite3@11.10.0 install node_modules/better-sqlite3 prebuild-install || node-gyp rebuild --release npm info run better-sqlite3@11.10.0 install { code: 1, signal: null } auth.js //Vanilla straight out of https://www.better-auth.com/docs/installation import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { db } from "@/db/drizzle"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", }), }); db.js //Vanilla straight out of https://orm.drizzle.team/docs/tutorials/drizzle-with-neon import { drizzle } from "drizzle-orm/neon-http"; import { neon } from "@neondatabase/serverless"; import { config } from "dotenv"; config({ path: ".env" }); // or .env.local const sql = neon(process.env.DATABASE_URL!); export const db = drizzle({ client: sql });
Author
Owner

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

Forgot to add, the same issue happens with Prisma.

@Cosina14 commented on GitHub (Sep 9, 2025): Forgot to add, the same issue happens with Prisma.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#1808