bug: postinstall script fails on windows with bun because of better-sqlite3 #2290

Closed
opened 2026-03-13 09:41:35 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @drago1520 on GitHub (Nov 12, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. bun add better-auth
  2. bun trust --all
  3. fail
    Message
bun pm trust v1.3.1 (89fa0f34)
  ⚙️  @prisma/engines [1/6]
C:\projects\nextjs_drizzle_better-auth\node_modules\better-sqlite3>if not defined npm_config_node_gyp (bun x --silent node-gyp rebuild --release )  else (node "" rebuild --release )


prebuild-install warn install No prebuilt binaries found (target=25.1.0 runtime=node arch=x64 libc= platform=win32)
gyp info it worked if it ends with ok
gyp info using node-gyp@12.0.0
gyp info using node@25.1.0 | win32 | x64
gyp info find Python using Python version 3.10.9 found at "C:\Users\Lenovo P51\AppData\Local\Programs\Python\Python310\python.exe"
gyp ERR! find VS
gyp ERR! find VS msvs_version not set from command line or npm config
gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details.
gyp ERR! find VS
gyp ERR! find VS Failure details: undefined
gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details.
gyp ERR! find VS
gyp ERR! find VS Failure details: undefined
gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21
gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21
gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21
gyp ERR! find VS not looking for VS2015 as it is only supported up to Node.js 18
gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8
gyp ERR! find VS
gyp ERR! find VS **************************************************************
gyp ERR! find VS You need to install the latest version of Visual Studio
gyp ERR! find VS including the "Desktop development with C++" workload.
gyp ERR! find VS For more information consult the documentation at:
gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows
gyp ERR! find VS **************************************************************
gyp ERR! find VS
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Visual Studio installation to use
gyp ERR! stack at VisualStudioFinder.fail (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\lib\find-visualstudio.js:118:11)
gyp ERR! stack at VisualStudioFinder.findVisualStudio (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\lib\find-visualstudio.js:74:17)
gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
gyp ERR! stack at async createBuildDir (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\lib\configure.js:112:18)
gyp ERR! stack at async run (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\bin\node-gyp.js:81:18)       
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\LENOVO~1\\AppData\\Local\\Temp\\bunx-2737838068-node-gyp@latest\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release"
gyp ERR! cwd C:\projects\nextjs_drizzle_better-auth\node_modules\better-sqlite3
gyp ERR! node -v v25.1.0
gyp ERR! node-gyp -v v12.0.0
gyp ERR! not ok

error: install script from "better-sqlite3" exited with 1

Current vs. Expected behavior

To be able to run postinstall scripts

What version of Better Auth are you using?

1.3.34

System info

npx @better-auth/cli info --json

Lenovo P51@DESKTOP-A9RES33 MINGW64 /c/projects/nextjs_drizzle_better-auth (main)
$ npx @better-auth/cli info
2025-11-12T09:27:30.891Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. TypeError: Invalid URL
    at new URL (node:internal/url:828:25)
    at C:\projects\nextjs_drizzle_better-auth\src\models\index.ts:15:41
    at async import (C:\projects\nextjs_drizzle_better-auth\node_modules\jiti\dist\jiti.cjs:1:158301)
    at async C:/projects/nextjs_drizzle_better-auth/src/lib/auth.ts:3:15
    at async Function.import (C:\projects\nextjs_drizzle_better-auth\node_modules\jiti\dist\jiti.cjs:1:158301)
    at async resolveConfig (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/c12/dist/index.mjs:320:20)
    at async loadConfig (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/c12/dist/index.mjs:149:22)
    at async getConfig (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/@better-auth/cli/dist/index.mjs:1990:30)
    at async getBetterAuthInfo (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/@better-auth/cli/dist/index.mjs:3313:22)
    at async Command.<anonymous> (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/@better-auth/cli/dist/index.mjs:3375:26) {
  code: 'ERR_INVALID_URL',
  input: 'undefined'
}

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

Package

Auth config (if applicable)

import { betterAuth } from 'better-auth';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { db, schema } from '@/models';
import { plugins } from './better-auth-plugins';

export const auth = betterAuth({
  emailAndPassword: {
    enabled: true,
  },
  socialProviders: {
    ...(process.env.GOOGLE_CLIENT_ID &&
      process.env.GOOGLE_CLIENT_SECRET && {
        google: {
          clientId: process.env.GOOGLE_CLIENT_ID,
          clientSecret: process.env.GOOGLE_CLIENT_SECRET,
          prompt: 'select_account',
        },
      }),
    ...(process.env.GITHUB_CLIENT_ID &&
      process.env.GITHUB_CLIENT_SECRET && {
        github: {
          clientId: process.env.GITHUB_CLIENT_ID,
          clientSecret: process.env.GITHUB_CLIENT_SECRET,
        },
      }),
  },

  database: drizzleAdapter(db, {
    provider: 'pg',
    usePlural: true,
    schema: schema,
  }),
  plugins,
  session: {
    expiresIn: 60 * 60 * 24 * 365, // 1 year
    cookieCache: {
      enabled: true,
      maxAge: 60 * 60, //? Instead of always hitting the db for session check.
    },
  },
});

Additional context

when I tried with pnpm

 pnpm approve-builds
√ Choose which packages to build (Press <space> to select, <a> to toggle all, <i> to invert selection) · @prisma/client, @prisma/engines, better-sqlite3, esbuild, prisma, sharp, unrs-resolver

√ The next packages will now be built: @prisma/client, @prisma/engines, better-sqlite3, esbuild, prisma, sharp, unrs-resolver.
Do you approve? (y/N) · true
node_modules/.pnpm/@prisma+engines@5.22.0/node_modules/@prisma/engines: Running postinstall script...
node_modules/.pnpm/esbuild@0.25.12/node_modules/esbuild: Running postinstall script, done in 326ms
node_modules/.pnpm/better-sqlite3@12.4.1/node_modules/better-sqlite3: Running install script, failed in 774ms
.../node_modules/better-sqlite3 install$ prebuild-install || node-gyp rebuild --release
│ prebuild-install warn install No prebuilt binaries found (target=25.1.0 runtime=node arch=x64 libc= platform=win32)
│ 'node-gyp' is not recognized as an internal or external command,
│ operable program or batch file.
└─ Failed in 774ms at C:\projects\nextjs_drizzle_better-auth\node_modules\.pnpm\better-sqlite3@12.4.1\node_modules\better-sqlite3
node_modules/.pnpm/unrs-resolver@1.11.1/node_modules/unrs-resolver: Running postinstall script, done in 302ms
node_modules/.pnpm/sharp@0.34.5/node_modules/sharp: Running install script, done in 203ms
 ELIFECYCLE  Command failed with exit code 1.
Originally created by @drago1520 on GitHub (Nov 12, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. `bun add better-auth` 2. `bun trust --all` 3. fail Message ```log bun pm trust v1.3.1 (89fa0f34) ⚙️ @prisma/engines [1/6] C:\projects\nextjs_drizzle_better-auth\node_modules\better-sqlite3>if not defined npm_config_node_gyp (bun x --silent node-gyp rebuild --release ) else (node "" rebuild --release ) prebuild-install warn install No prebuilt binaries found (target=25.1.0 runtime=node arch=x64 libc= platform=win32) gyp info it worked if it ends with ok gyp info using node-gyp@12.0.0 gyp info using node@25.1.0 | win32 | x64 gyp info find Python using Python version 3.10.9 found at "C:\Users\Lenovo P51\AppData\Local\Programs\Python\Python310\python.exe" gyp ERR! find VS gyp ERR! find VS msvs_version not set from command line or npm config gyp ERR! find VS VCINSTALLDIR not set, not running in VS Command Prompt gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details. gyp ERR! find VS gyp ERR! find VS Failure details: undefined gyp ERR! find VS could not use PowerShell to find Visual Studio 2017 or newer, try re-running with '--loglevel silly' for more details. gyp ERR! find VS gyp ERR! find VS Failure details: undefined gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21 gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21 gyp ERR! find VS not looking for VS2017 as it is only supported up to Node.js 21 gyp ERR! find VS not looking for VS2015 as it is only supported up to Node.js 18 gyp ERR! find VS not looking for VS2013 as it is only supported up to Node.js 8 gyp ERR! find VS gyp ERR! find VS ************************************************************** gyp ERR! find VS You need to install the latest version of Visual Studio gyp ERR! find VS including the "Desktop development with C++" workload. gyp ERR! find VS For more information consult the documentation at: gyp ERR! find VS https://github.com/nodejs/node-gyp#on-windows gyp ERR! find VS ************************************************************** gyp ERR! find VS gyp ERR! configure error gyp ERR! stack Error: Could not find any Visual Studio installation to use gyp ERR! stack at VisualStudioFinder.fail (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\lib\find-visualstudio.js:118:11) gyp ERR! stack at VisualStudioFinder.findVisualStudio (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\lib\find-visualstudio.js:74:17) gyp ERR! stack at process.processTicksAndRejections (node:internal/process/task_queues:103:5) gyp ERR! stack at async createBuildDir (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\lib\configure.js:112:18) gyp ERR! stack at async run (C:\Users\LENOVO~1\AppData\Local\Temp\bunx-2737838068-node-gyp@latest\node_modules\node-gyp\bin\node-gyp.js:81:18) gyp ERR! System Windows_NT 10.0.19045 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\LENOVO~1\\AppData\\Local\\Temp\\bunx-2737838068-node-gyp@latest\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--release" gyp ERR! cwd C:\projects\nextjs_drizzle_better-auth\node_modules\better-sqlite3 gyp ERR! node -v v25.1.0 gyp ERR! node-gyp -v v12.0.0 gyp ERR! not ok error: install script from "better-sqlite3" exited with 1 ``` ### Current vs. Expected behavior To be able to run postinstall scripts ### What version of Better Auth are you using? 1.3.34 ### System info ```bash npx @better-auth/cli info --json Lenovo P51@DESKTOP-A9RES33 MINGW64 /c/projects/nextjs_drizzle_better-auth (main) $ npx @better-auth/cli info 2025-11-12T09:27:30.891Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. TypeError: Invalid URL at new URL (node:internal/url:828:25) at C:\projects\nextjs_drizzle_better-auth\src\models\index.ts:15:41 at async import (C:\projects\nextjs_drizzle_better-auth\node_modules\jiti\dist\jiti.cjs:1:158301) at async C:/projects/nextjs_drizzle_better-auth/src/lib/auth.ts:3:15 at async Function.import (C:\projects\nextjs_drizzle_better-auth\node_modules\jiti\dist\jiti.cjs:1:158301) at async resolveConfig (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/c12/dist/index.mjs:320:20) at async loadConfig (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/c12/dist/index.mjs:149:22) at async getConfig (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/@better-auth/cli/dist/index.mjs:1990:30) at async getBetterAuthInfo (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/@better-auth/cli/dist/index.mjs:3313:22) at async Command.<anonymous> (file:///C:/projects/nextjs_drizzle_better-auth/node_modules/@better-auth/cli/dist/index.mjs:3375:26) { code: 'ERR_INVALID_URL', input: 'undefined' } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { db, schema } from '@/models'; import { plugins } from './better-auth-plugins'; export const auth = betterAuth({ emailAndPassword: { enabled: true, }, socialProviders: { ...(process.env.GOOGLE_CLIENT_ID && process.env.GOOGLE_CLIENT_SECRET && { google: { clientId: process.env.GOOGLE_CLIENT_ID, clientSecret: process.env.GOOGLE_CLIENT_SECRET, prompt: 'select_account', }, }), ...(process.env.GITHUB_CLIENT_ID && process.env.GITHUB_CLIENT_SECRET && { github: { clientId: process.env.GITHUB_CLIENT_ID, clientSecret: process.env.GITHUB_CLIENT_SECRET, }, }), }, database: drizzleAdapter(db, { provider: 'pg', usePlural: true, schema: schema, }), plugins, session: { expiresIn: 60 * 60 * 24 * 365, // 1 year cookieCache: { enabled: true, maxAge: 60 * 60, //? Instead of always hitting the db for session check. }, }, }); ``` ### Additional context when I tried with pnpm ```log pnpm approve-builds √ Choose which packages to build (Press <space> to select, <a> to toggle all, <i> to invert selection) · @prisma/client, @prisma/engines, better-sqlite3, esbuild, prisma, sharp, unrs-resolver √ The next packages will now be built: @prisma/client, @prisma/engines, better-sqlite3, esbuild, prisma, sharp, unrs-resolver. Do you approve? (y/N) · true node_modules/.pnpm/@prisma+engines@5.22.0/node_modules/@prisma/engines: Running postinstall script... node_modules/.pnpm/esbuild@0.25.12/node_modules/esbuild: Running postinstall script, done in 326ms node_modules/.pnpm/better-sqlite3@12.4.1/node_modules/better-sqlite3: Running install script, failed in 774ms .../node_modules/better-sqlite3 install$ prebuild-install || node-gyp rebuild --release │ prebuild-install warn install No prebuilt binaries found (target=25.1.0 runtime=node arch=x64 libc= platform=win32) │ 'node-gyp' is not recognized as an internal or external command, │ operable program or batch file. └─ Failed in 774ms at C:\projects\nextjs_drizzle_better-auth\node_modules\.pnpm\better-sqlite3@12.4.1\node_modules\better-sqlite3 node_modules/.pnpm/unrs-resolver@1.11.1/node_modules/unrs-resolver: Running postinstall script, done in 302ms node_modules/.pnpm/sharp@0.34.5/node_modules/sharp: Running install script, done in 203ms  ELIFECYCLE  Command failed with exit code 1. ```
GiteaMirror added the bug label 2026-03-13 09:41:35 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Nov 12, 2025):

Tag @better-auth-agent if you would like an answer from the Agent

DiagramDiscordGitHub

Diagram Join Star

@better-auth-agent[bot] commented on GitHub (Nov 12, 2025): Tag @better-auth-agent if you would like an answer from the Agent <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) • [Discord](https://discord.gg/better-auth) • [GitHub](https://github.com/better-auth/better-auth) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/better-auth_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/better-auth) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/better-auth/better-auth)
Author
Owner

@dosubot[bot] commented on GitHub (Nov 12, 2025):

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

This is a known issue: better-sqlite3 requires native compilation (with node-gyp, Python, and Visual Studio build tools) and is included as a dependency of better-auth, even if you’re not using SQLite (for example, with drizzleAdapter and Postgres). Bun and npm will always attempt to install all dependencies, so you’ll hit this error on Windows if the build tools aren’t present, or if Bun’s native module support is incomplete for better-sqlite3. pnpm sometimes avoids this by hoisting dependencies differently, but not always—especially if you approve builds or use certain CLI features.

There’s currently no logic in better-auth to skip installing better-sqlite3 when you’re not using SQLite, so this affects all users on platforms where native builds are tricky or unsupported (source, source).

Workarounds:

  • Use pnpm instead of Bun or npm, as it may avoid installing unnecessary native modules.
  • If you must use Bun or npm, you’ll need to have Python and Visual Studio with the C++ workload installed on Windows.
  • For Docker or CI, use a multi-stage build: install build tools in a builder stage, run the install, then copy only the built output to a slim image (example workaround).
  • If you don’t need new features, pin better-auth to 1.3.27 or earlier, which used an older better-sqlite3 version that may be less strict about native builds (source).

There’s currently no official fix for this in better-auth, but maintainers recommend pnpm or a multi-stage Docker build to avoid these issues.

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 (Nov 12, 2025): <!-- Greeting --> Hi @drago1520! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue: better-sqlite3 requires native compilation (with node-gyp, Python, and Visual Studio build tools) and is included as a dependency of better-auth, even if you’re not using SQLite (for example, with drizzleAdapter and Postgres). Bun and npm will always attempt to install all dependencies, so you’ll hit this error on Windows if the build tools aren’t present, or if Bun’s native module support is incomplete for better-sqlite3. pnpm sometimes avoids this by hoisting dependencies differently, but not always—especially if you approve builds or use certain CLI features. There’s currently no logic in better-auth to skip installing better-sqlite3 when you’re not using SQLite, so this affects all users on platforms where native builds are tricky or unsupported ([source](https://github.com/better-auth/better-auth/issues/4305), [source](https://github.com/better-auth/better-auth/issues/2283)). Workarounds: - Use pnpm instead of Bun or npm, as it may avoid installing unnecessary native modules. - If you must use Bun or npm, you’ll need to have Python and Visual Studio with the C++ workload installed on Windows. - For Docker or CI, use a multi-stage build: install build tools in a builder stage, run the install, then copy only the built output to a slim image ([example workaround](https://github.com/better-auth/better-auth/issues/2283)). - If you don’t need new features, pin better-auth to 1.3.27 or earlier, which used an older better-sqlite3 version that may be less strict about native builds ([source](https://github.com/better-auth/better-auth/issues/5461)). There’s currently no official fix for this in better-auth, but maintainers recommend pnpm or a multi-stage Docker build to avoid these issues. <!-- 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/ad8414e9-95ef-47f7-b535-08411c16efec?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/ad8414e9-95ef-47f7-b535-08411c16efec?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/ad8414e9-95ef-47f7-b535-08411c16efec?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/ad8414e9-95ef-47f7-b535-08411c16efec?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/ad8414e9-95ef-47f7-b535-08411c16efec?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/ad8414e9-95ef-47f7-b535-08411c16efec?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/ad8414e9-95ef-47f7-b535-08411c16efec?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/5928)
Author
Owner

@drago1520 commented on GitHub (Nov 12, 2025):

I found it. I was using nodejs 25. Switching to 24 LTS did the trick. A helpful error message came from npm when I tried to install, saying that better-sqlite3 supports node 22-24.

@drago1520 commented on GitHub (Nov 12, 2025): I found it. I was using nodejs 25. Switching to 24 LTS did the trick. A helpful error message came from npm when I tried to install, saying that better-sqlite3 supports node 22-24.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2290