[GH-ISSUE #3951] Cannot use better-auth cli to generate schema #18404

Closed
opened 2026-04-15 16:51:52 -05:00 by GiteaMirror · 30 comments
Owner

Originally created by @l0seq on GitHub (Aug 12, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3951

Originally assigned to: @himself65 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Run bunx --bun @better-auth/cli generate --config src/auth/index.ts
  2. CLI will return: Cannot find module 'zod/v4' from '/tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs'

Current vs. Expected behavior

Migrations should be generated normally as expected, but this error is returned.

What version of Better Auth are you using?

1.3.5

System info

System:
    OS: Linux 6.12 Manjaro Linux
    CPU: (12) x64 AMD Ryzen 5 5600H with Radeon Graphics
    Memory: 18.50 GB / 30.21 GB
    Container: Yes
    Shell: 5.9 - /bin/zsh
  Browsers:
    Chromium: 138.0.7204.157

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 "../database";
import { account, appInvitation, session, user, verification } from "../database/schema";
import { admin } from "better-auth/plugins";
import { appInvite } from "@better-auth-kit/app-invite"

export const auth = betterAuth({
    database: drizzleAdapter(db, {
        provider: "sqlite",
        schema: {
            user,
            account,
            session,
            verification,
            appInvitation
        },
    }),
    emailAndPassword: {
        enabled: true,
        disableSignUp: false,
    },
    plugins: [
        admin(),
        appInvite({
            sendInvitationEmail: async (data) => {
                /*  WIP */
            },
            allowUserToCreateInvitation: (user) => {
                return true;
                /*  WIP */
            }
        })
    ]
});

Additional context

I have tested it with npx and bunx, same behavior

Originally created by @l0seq on GitHub (Aug 12, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3951 Originally assigned to: @himself65 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1. Run `bunx --bun @better-auth/cli generate --config src/auth/index.ts` 2. CLI will return: `Cannot find module 'zod/v4' from '/tmp/bunx-1000-@better-auth/cli@latest/node_modules/@better-auth/cli/dist/index.mjs'` ### Current vs. Expected behavior Migrations should be generated normally as expected, but this error is returned. ### What version of Better Auth are you using? 1.3.5 ### System info ```bash System: OS: Linux 6.12 Manjaro Linux CPU: (12) x64 AMD Ryzen 5 5600H with Radeon Graphics Memory: 18.50 GB / 30.21 GB Container: Yes Shell: 5.9 - /bin/zsh Browsers: Chromium: 138.0.7204.157 ``` ### 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 "../database"; import { account, appInvitation, session, user, verification } from "../database/schema"; import { admin } from "better-auth/plugins"; import { appInvite } from "@better-auth-kit/app-invite" export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "sqlite", schema: { user, account, session, verification, appInvitation }, }), emailAndPassword: { enabled: true, disableSignUp: false, }, plugins: [ admin(), appInvite({ sendInvitationEmail: async (data) => { /* WIP */ }, allowUserToCreateInvitation: (user) => { return true; /* WIP */ } }) ] }); ``` ### Additional context I have tested it with npx and bunx, same behavior
GiteaMirror added the lockedbug labels 2026-04-15 16:51:53 -05:00
Author
Owner

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

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

This is a known issue caused by the Better Auth CLI importing Zod using the deprecated path zod/v4, which is no longer available in recent Zod versions. That's why you see the "Cannot find module 'zod/v4'" error when running the CLI ref.

Workarounds you can try:

  • Patch your local CLI install: In node_modules/@better-auth/cli/dist/index.mjs, change import * as z from 'zod/v4' to import * as z from 'zod'. This usually works unless there are other Zod compatibility issues.
  • Pin Zod to an older version that still exports the v4 subpath, such as zod@4.0.10 ref. You can do this by running:
    npm install zod@4.0.10
    
    or with your package manager of choice.
  • If you use a monorepo or have Zod in multiple places, make sure all packages use the exact same Zod version to avoid runtime issues ref.

The maintainers are aware of the problem and are working on a fix. Keep an eye out for updates to @better-auth/cli that address this ref.

Let me know if you need step-by-step instructions for any of these workarounds.

To reply, just mention @dosu.


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

<!-- gh-comment-id:3179468385 --> @dosubot[bot] commented on GitHub (Aug 12, 2025): <!-- Greeting --> Hi @l0seq! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue caused by the Better Auth CLI importing Zod using the deprecated path `zod/v4`, which is no longer available in recent Zod versions. That's why you see the "Cannot find module 'zod/v4'" error when running the CLI [ref](https://github.com/better-auth/better-auth/issues/3614#issuecomment-3119723471). Workarounds you can try: - Patch your local CLI install: In `node_modules/@better-auth/cli/dist/index.mjs`, change `import * as z from 'zod/v4'` to `import * as z from 'zod'`. This usually works unless there are other Zod compatibility issues. - Pin Zod to an older version that still exports the `v4` subpath, such as `zod@4.0.10` [ref](https://github.com/better-auth/better-auth/issues/3570#issuecomment-3135115238). You can do this by running: ``` npm install zod@4.0.10 ``` or with your package manager of choice. - If you use a monorepo or have Zod in multiple places, make sure all packages use the exact same Zod version to avoid runtime issues [ref](https://github.com/better-auth/better-auth/issues/3570#issuecomment-3120732965). The maintainers are aware of the problem and are working on a fix. Keep an eye out for updates to `@better-auth/cli` that address this [ref](https://github.com/better-auth/better-auth/issues/3614#issuecomment-3119723471). Let me know if you need step-by-step instructions for any of these workarounds. <!-- 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/2a7b006c-0b63-48ec-8a11-01eeb3798694?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2a7b006c-0b63-48ec-8a11-01eeb3798694?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2a7b006c-0b63-48ec-8a11-01eeb3798694?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2a7b006c-0b63-48ec-8a11-01eeb3798694?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2a7b006c-0b63-48ec-8a11-01eeb3798694?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2a7b006c-0b63-48ec-8a11-01eeb3798694?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2a7b006c-0b63-48ec-8a11-01eeb3798694?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/3951)
Author
Owner

@Kinfe123 commented on GitHub (Aug 12, 2025):

can you provide me a repro for this issue. this should have been resolved by the previous PR.

<!-- gh-comment-id:3179691798 --> @Kinfe123 commented on GitHub (Aug 12, 2025): can you provide me a repro for this issue. this should have been resolved by the previous PR.
Author
Owner

@hannesfant commented on GitHub (Aug 12, 2025):

I believe this might be isolated to Bun, I'm having the same issue in a fresh terminal (& project) with bunx, while npx seems to work. The downside is that we're using Bun's sql driver, so the script is still failing on a bun:sql import, though it's at least running without any zod import errors

<!-- gh-comment-id:3179793126 --> @hannesfant commented on GitHub (Aug 12, 2025): I believe this might be isolated to Bun, I'm having the same issue in a fresh terminal (& project) with bunx, while npx seems to work. The downside is that we're using Bun's sql driver, so the script is still failing on a bun:sql import, though it's at least running without any zod import errors
Author
Owner

@l0seq commented on GitHub (Aug 12, 2025):

can you provide me a repro for this issue. this should have been resolved by the previous PR.

I can't @Kinfe123, the problem just happens when i launch the command, no particular behavior

I believe this might be isolated to Bun, I'm having the same issue in a fresh terminal (& project) with bunx, while npx seems to work. The downside is that we're using Bun's sql driver, so the script is still failing on a bun:sql import, though it's at least running without any zod import errors

@hannesfant you are right, i have retried with npm and i have this error:

2025-08-12T16:55:36.046Z ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun:sqlite'

UPDATE: when i try with better-auth cli 1.3.4 with this command:

bunx --bun @better-auth/cli@1.3.4 generate --config src/auth/index.ts

It works without any problem, so i think it's a problem with 1.3.5

<!-- gh-comment-id:3180224338 --> @l0seq commented on GitHub (Aug 12, 2025): > can you provide me a repro for this issue. this should have been resolved by the previous PR. I can't @Kinfe123, the problem just happens when i launch the command, no particular behavior > I believe this might be isolated to Bun, I'm having the same issue in a fresh terminal (& project) with bunx, while npx seems to work. The downside is that we're using Bun's sql driver, so the script is still failing on a bun:sql import, though it's at least running without any zod import errors @hannesfant you are right, i have retried with npm and i have this error: `2025-08-12T16:55:36.046Z ERROR [Better Auth]: Couldn't read your auth config. Error: Cannot find module 'bun:sqlite'` UPDATE: when i try with better-auth cli 1.3.4 with this command: `bunx --bun @better-auth/cli@1.3.4 generate --config src/auth/index.ts` It works without any problem, so i think it's a problem with 1.3.5
Author
Owner

@dmythro commented on GitHub (Aug 12, 2025):

UPDATE: when i try with better-auth cli 1.3.4 with this command:

bunx --bun @better-auth/cli@1.3.4 generate --config src/auth/index.ts

It works without any problem, so i think it's a problem with 1.3.5

Thanks for mentioning cli 1.3.4, saved a lot of time for me now!

<!-- gh-comment-id:3180842973 --> @dmythro commented on GitHub (Aug 12, 2025): > UPDATE: when i try with better-auth cli 1.3.4 with this command: > > `bunx --bun @better-auth/cli@1.3.4 generate --config src/auth/index.ts` > > It works without any problem, so i think it's a problem with 1.3.5 Thanks for mentioning `cli 1.3.4`, saved a lot of time for me now!
Author
Owner

@timothyallan commented on GitHub (Aug 13, 2025):

I'm also getting this on node with "better-auth": "^1.3.6", FWIW

npx @better-auth/cli migrate

Need to install the following packages:
@better-auth/cli@1.3.6
Ok to proceed? (y) y

node:internal/modules/esm/resolve:854
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from /Users/ta/.npm/_npx/167ca1f116d365e6/node_modules/@better-auth/cli/dist/index.mjs
    at packageResolve (node:internal/modules/esm/resolve:854:9)
    at moduleResolve (node:internal/modules/esm/resolve:927:18)
    at defaultResolve (node:internal/modules/esm/resolve:1169:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:540:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:509:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40)
    at link (node:internal/modules/esm/module_job:95:36) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v20.17.0
<!-- gh-comment-id:3186067393 --> @timothyallan commented on GitHub (Aug 13, 2025): I'm also getting this on node with `"better-auth": "^1.3.6",` FWIW ``` npx @better-auth/cli migrate Need to install the following packages: @better-auth/cli@1.3.6 Ok to proceed? (y) y node:internal/modules/esm/resolve:854 throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null); ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from /Users/ta/.npm/_npx/167ca1f116d365e6/node_modules/@better-auth/cli/dist/index.mjs at packageResolve (node:internal/modules/esm/resolve:854:9) at moduleResolve (node:internal/modules/esm/resolve:927:18) at defaultResolve (node:internal/modules/esm/resolve:1169:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:540:12) at ModuleLoader.resolve (node:internal/modules/esm/loader:509:25) at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:239:38) at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:96:40) at link (node:internal/modules/esm/module_job:95:36) { code: 'ERR_MODULE_NOT_FOUND' } Node.js v20.17.0 ```
Author
Owner

@Kinfe123 commented on GitHub (Aug 13, 2025):

@timothyallan can you try updating your node version ?

<!-- gh-comment-id:3186105605 --> @Kinfe123 commented on GitHub (Aug 13, 2025): @timothyallan can you try updating your node version ?
Author
Owner

@timothyallan commented on GitHub (Aug 13, 2025):

Sure, updated to the latest LTS version with same result with 1.3.6, 1.3.4 works well.

npx @better-auth/cli migrate       
node:internal/modules/package_json_reader:255
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from /Users/ta/.npm/_npx/167ca1f116d365e6/node_modules/@better-auth/cli/dist/index.mjs
    at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9)
    at packageResolve (node:internal/modules/esm/resolve:767:81)
    at moduleResolve (node:internal/modules/esm/resolve:853:18)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:783:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:707:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:690:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:183:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Node.js v22.18.0

npx @better-auth/cli@1.3.4 migrate                                                                                                                                          
⠋ preparing migration...[2025-08-13T23:16:18.853Z] [warn] ....
<!-- gh-comment-id:3186152837 --> @timothyallan commented on GitHub (Aug 13, 2025): Sure, updated to the latest LTS version with same result with 1.3.6, 1.3.4 works well. ``` npx @better-auth/cli migrate node:internal/modules/package_json_reader:255 throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null); ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from /Users/ta/.npm/_npx/167ca1f116d365e6/node_modules/@better-auth/cli/dist/index.mjs at Object.getPackageJSONURL (node:internal/modules/package_json_reader:255:9) at packageResolve (node:internal/modules/esm/resolve:767:81) at moduleResolve (node:internal/modules/esm/resolve:853:18) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:783:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:707:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:690:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38) at ModuleJob._link (node:internal/modules/esm/module_job:183:49) { code: 'ERR_MODULE_NOT_FOUND' } Node.js v22.18.0 npx @better-auth/cli@1.3.4 migrate ⠋ preparing migration...[2025-08-13T23:16:18.853Z] [warn] .... ```
Author
Owner

@Kinfe123 commented on GitHub (Aug 13, 2025):

i cant seems to reproduce it. can you please do a minimal repro for this if possible. since your issue is also different from the author itself.

<!-- gh-comment-id:3186172690 --> @Kinfe123 commented on GitHub (Aug 13, 2025): i cant seems to reproduce it. can you please do a minimal repro for this if possible. since your issue is also different from the author itself.
Author
Owner

@Rhayxz commented on GitHub (Aug 14, 2025):

i cant seems to reproduce it. can you please ship a minimal repro for this if possible. since your issue is also different from the author itself.

Got the same issue, and fix was to revert to 1.3.4 and under. As you can see below, it works with 1.3.4 and down, but errors on 1.3.5 and above:

Running with v1.2.12:

root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.2.12 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y
2025-08-14T19:50:57.966Z SUCCESS [Better Auth]: 🚀 Schema was overwritten successfully!

---
Running with v1.3.4:
root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.3.4 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y
✔ The file src/db/auth.schema.ts already exists. Do you want to overwrite the schema to the file? … yes
2025-08-14T19:51:02.561Z SUCCESS [Better Auth]: 🚀 Schema was overwritten successfully!

---
Running with v1.3.5:
root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.3.5 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y
node:internal/modules/esm/resolve:274
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/tmp/bunx-0-@better-auth/cli@1.3.5/node_modules/zod/dist/esm/v4/index.js' imported from /tmp/bunx-0-@better-auth/cli@1.3.5/node_modules/@better-auth/cli/dist/index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:859:10)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
    at #link (node:internal/modules/esm/module_job:163:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///tmp/bunx-0-@better-auth/cli@1.3.5/node_modules/zod/dist/esm/v4/index.js'
}

Node.js v24.0.2

---
Running with v1.3.6:
root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.3.6 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y
node:internal/modules/esm/resolve:274
    throw new ERR_MODULE_NOT_FOUND(
          ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/tmp/bunx-0-@better-auth/cli@1.3.6/node_modules/zod/dist/esm/v4/index.js' imported from /tmp/bunx-0-@better-auth/cli@1.3.6/node_modules/@better-auth/cli/dist/index.mjs
    at finalizeResolution (node:internal/modules/esm/resolve:274:11)
    at moduleResolve (node:internal/modules/esm/resolve:859:10)
    at defaultResolve (node:internal/modules/esm/resolve:983:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38)
    at #link (node:internal/modules/esm/module_job:163:49) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///tmp/bunx-0-@better-auth/cli@1.3.6/node_modules/zod/dist/esm/v4/index.js'
}

Node.js v24.0.2
<!-- gh-comment-id:3189702635 --> @Rhayxz commented on GitHub (Aug 14, 2025): > i cant seems to reproduce it. can you please ship a minimal repro for this if possible. since your issue is also different from the author itself. Got the same issue, and fix was to revert to 1.3.4 and under. As you can see below, it works with 1.3.4 and down, but errors on 1.3.5 and above: ``` Running with v1.2.12: root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.2.12 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y 2025-08-14T19:50:57.966Z SUCCESS [Better Auth]: 🚀 Schema was overwritten successfully! --- Running with v1.3.4: root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.3.4 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y ✔ The file src/db/auth.schema.ts already exists. Do you want to overwrite the schema to the file? … yes 2025-08-14T19:51:02.561Z SUCCESS [Better Auth]: 🚀 Schema was overwritten successfully! --- Running with v1.3.5: root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.3.5 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y node:internal/modules/esm/resolve:274 throw new ERR_MODULE_NOT_FOUND( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/tmp/bunx-0-@better-auth/cli@1.3.5/node_modules/zod/dist/esm/v4/index.js' imported from /tmp/bunx-0-@better-auth/cli@1.3.5/node_modules/@better-auth/cli/dist/index.mjs at finalizeResolution (node:internal/modules/esm/resolve:274:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38) at #link (node:internal/modules/esm/module_job:163:49) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///tmp/bunx-0-@better-auth/cli@1.3.5/node_modules/zod/dist/esm/v4/index.js' } Node.js v24.0.2 --- Running with v1.3.6: root@Computer:/home/me/projects/proj-1/apps/api# bunx @better-auth/cli@1.3.6 generate --config src/auth/better-auth.config.ts --output src/db/auth.schema.ts -y node:internal/modules/esm/resolve:274 throw new ERR_MODULE_NOT_FOUND( ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/tmp/bunx-0-@better-auth/cli@1.3.6/node_modules/zod/dist/esm/v4/index.js' imported from /tmp/bunx-0-@better-auth/cli@1.3.6/node_modules/@better-auth/cli/dist/index.mjs at finalizeResolution (node:internal/modules/esm/resolve:274:11) at moduleResolve (node:internal/modules/esm/resolve:859:10) at defaultResolve (node:internal/modules/esm/resolve:983:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:799:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:723:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:706:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:307:38) at #link (node:internal/modules/esm/module_job:163:49) { code: 'ERR_MODULE_NOT_FOUND', url: 'file:///tmp/bunx-0-@better-auth/cli@1.3.6/node_modules/zod/dist/esm/v4/index.js' } Node.js v24.0.2 ```
Author
Owner

@Kinfe123 commented on GitHub (Aug 14, 2025):

Have you installed zod ? and what version is this ?. it is currently peerDep.

<!-- gh-comment-id:3189804543 --> @Kinfe123 commented on GitHub (Aug 14, 2025): Have you installed zod ? and what version is this ?. it is currently peerDep.
Author
Owner

@elartix commented on GitHub (Aug 17, 2025):

hi, @Bekacru

Ok to proceed? (y) y

node:internal/modules/esm/resolve:873
  throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null);
        ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from C:\Users\MYUSER\AppData\Local\npm-cache\_npx\05eee8cc65087e98\node_modules\@better-auth\cli\dist\index.mjs
    at packageResolve (node:internal/modules/esm/resolve:873:9)
    at moduleResolve (node:internal/modules/esm/resolve:946:18)
    at defaultResolve (node:internal/modules/esm/resolve:1188:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:642:12)
    at #cachedDefaultResolve (node:internal/modules/esm/loader:591:25)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:574:38)
    at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:236:38)
    at ModuleJob._link (node:internal/modules/esm/module_job:130:49) {
  code: 'ERR_MODULE_NOT_FOUND'
}

Zod not installed in npx cache folder \AppData\Local\npm-cache\_npx\05eee8cc65087e98\node_modules\

Image

Workaround

  1. install @better-auth/cli as global package (will be installed with zod)
  2. Create custom scripts and add into node folder, (in my case C:\Users\MYUSER\AppData\Roaming\nvm\v20.19.3)

better-auth

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*|*MINGW*|*MSYS*)
        if command -v cygpath > /dev/null 2>&1; then
            basedir=`cygpath -w "$basedir"`
        fi
    ;;
esac

if [ -x "$basedir/node" ]; then
  exec "$basedir/node"  "$basedir/node_modules/@better-auth/cli/dist/index.mjs" "$@"
else 
  exec node  "$basedir/node_modules/@better-auth/cli/dist/index.mjs" "$@"
fi

better-auth.cmd

@ECHO off
GOTO start
:find_dp0
SET dp0=%~dp0
EXIT /b
:start
SETLOCAL
CALL :find_dp0

IF EXIST "%dp0%\node.exe" (
  SET "_prog=%dp0%\node.exe"
) ELSE (
  SET "_prog=node"
  SET PATHEXT=%PATHEXT:;.JS;=;%
)

endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%"  "%dp0%\node_modules\@better-auth\cli\dist\index.mjs" %*

better-auth.ps1

#!/usr/bin/env pwsh
$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent

$exe=""
if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {
  # Fix case when both the Windows and Linux builds of Node
  # are installed in the same directory
  $exe=".exe"
}
$ret=0
if (Test-Path "$basedir/node$exe") {
  # Support pipeline input
  if ($MyInvocation.ExpectingInput) {
    $input | & "$basedir/node$exe"  "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args
  } else {
    & "$basedir/node$exe"  "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args
  }
  $ret=$LASTEXITCODE
} else {
  # Support pipeline input
  if ($MyInvocation.ExpectingInput) {
    $input | & "node$exe"  "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args
  } else {
    & "node$exe"  "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args
  }
  $ret=$LASTEXITCODE
}
exit $ret

Run:

better-auth generate ...

better-auth.cmd.txt
better-auth.ps1.txt
better-auth.txt

I guess will be fixed soon

<!-- gh-comment-id:3194605319 --> @elartix commented on GitHub (Aug 17, 2025): hi, @Bekacru ```@better-auth/cli@1.3.7 Ok to proceed? (y) y node:internal/modules/esm/resolve:873 throw new ERR_MODULE_NOT_FOUND(packageName, fileURLToPath(base), null); ^ Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'zod' imported from C:\Users\MYUSER\AppData\Local\npm-cache\_npx\05eee8cc65087e98\node_modules\@better-auth\cli\dist\index.mjs at packageResolve (node:internal/modules/esm/resolve:873:9) at moduleResolve (node:internal/modules/esm/resolve:946:18) at defaultResolve (node:internal/modules/esm/resolve:1188:11) at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:642:12) at #cachedDefaultResolve (node:internal/modules/esm/loader:591:25) at ModuleLoader.resolve (node:internal/modules/esm/loader:574:38) at ModuleLoader.getModuleJobForImport (node:internal/modules/esm/loader:236:38) at ModuleJob._link (node:internal/modules/esm/module_job:130:49) { code: 'ERR_MODULE_NOT_FOUND' } ``` Zod not installed in npx cache folder `\AppData\Local\npm-cache\_npx\05eee8cc65087e98\node_modules\` <img width="427" height="565" alt="Image" src="https://github.com/user-attachments/assets/b92289a6-e496-4d56-961e-5b5f189dff3d" /> # Workaround 1. install `@better-auth/cli` as global package (will be installed with zod) 2. Create custom scripts and add into node folder, (in my case `C:\Users\MYUSER\AppData\Roaming\nvm\v20.19.3`) **better-auth** ``` #!/bin/sh basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')") case `uname` in *CYGWIN*|*MINGW*|*MSYS*) if command -v cygpath > /dev/null 2>&1; then basedir=`cygpath -w "$basedir"` fi ;; esac if [ -x "$basedir/node" ]; then exec "$basedir/node" "$basedir/node_modules/@better-auth/cli/dist/index.mjs" "$@" else exec node "$basedir/node_modules/@better-auth/cli/dist/index.mjs" "$@" fi ``` **better-auth.cmd** ``` @ECHO off GOTO start :find_dp0 SET dp0=%~dp0 EXIT /b :start SETLOCAL CALL :find_dp0 IF EXIST "%dp0%\node.exe" ( SET "_prog=%dp0%\node.exe" ) ELSE ( SET "_prog=node" SET PATHEXT=%PATHEXT:;.JS;=;% ) endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & "%_prog%" "%dp0%\node_modules\@better-auth\cli\dist\index.mjs" %* ``` **better-auth.ps1** ``` #!/usr/bin/env pwsh $basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent $exe="" if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) { # Fix case when both the Windows and Linux builds of Node # are installed in the same directory $exe=".exe" } $ret=0 if (Test-Path "$basedir/node$exe") { # Support pipeline input if ($MyInvocation.ExpectingInput) { $input | & "$basedir/node$exe" "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args } else { & "$basedir/node$exe" "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args } $ret=$LASTEXITCODE } else { # Support pipeline input if ($MyInvocation.ExpectingInput) { $input | & "node$exe" "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args } else { & "node$exe" "$basedir/node_modules/@better-auth/cli/dist/index.mjs" $args } $ret=$LASTEXITCODE } exit $ret ``` Run: ``` better-auth generate ... ``` [better-auth.cmd.txt](https://github.com/user-attachments/files/21824250/better-auth.cmd.txt) [better-auth.ps1.txt](https://github.com/user-attachments/files/21824252/better-auth.ps1.txt) [better-auth.txt](https://github.com/user-attachments/files/21824251/better-auth.txt) I guess will be fixed soon
Author
Owner

@Kinfe123 commented on GitHub (Aug 18, 2025):

It is peerDep right now. We don't bundle zod with the cli. You should install the version you want to avoid version mismatch but we have mention the range version on peerDep value. Please can you try installing and see if the issue persists

<!-- gh-comment-id:3195083687 --> @Kinfe123 commented on GitHub (Aug 18, 2025): It is peerDep right now. We don't bundle zod with the cli. You should install the version you want to avoid version mismatch but we have mention the range version on peerDep value. Please can you try installing and see if the issue persists
Author
Owner

@Kinfe123 commented on GitHub (Aug 18, 2025):

Or give me a reproducible if installing your zod version does not work ?

<!-- gh-comment-id:3195087006 --> @Kinfe123 commented on GitHub (Aug 18, 2025): Or give me a reproducible if installing your zod version does not work ?
Author
Owner

@bunday commented on GitHub (Aug 18, 2025):

I can confirm using better-auth/cli@1.3.4 solves the problem for now

<!-- gh-comment-id:3196898196 --> @bunday commented on GitHub (Aug 18, 2025): I can confirm using `better-auth/cli@1.3.4` solves the problem for now
Author
Owner

@himself65 commented on GitHub (Aug 19, 2025):

Have you installed zod ? and what version is this ?. it is currently peerDep.

In some case, pnpm won't install peerDepp afai, not sure if this is related

<!-- gh-comment-id:3201784876 --> @himself65 commented on GitHub (Aug 19, 2025): > Have you installed zod ? and what version is this ?. it is currently peerDep. In some case, pnpm won't install peerDepp afai, not sure if this is related
Author
Owner

@himself65 commented on GitHub (Aug 19, 2025):

maybe related https://github.com/oven-sh/bun/issues/16970

<!-- gh-comment-id:3202191079 --> @himself65 commented on GitHub (Aug 19, 2025): maybe related https://github.com/oven-sh/bun/issues/16970
Author
Owner

@nicognaW commented on GitHub (Aug 20, 2025):

i had the same issue with bunx before. checked my bunx dir and found zod at 3.25.0. and i saw here

d921471a74/packages/cli/package.json (L67)

that @better-auth/cli's peer dep requires "zod": "3.25.0 || ^4.0.0".

guessing bun installed the first match 3.25.0, but my project uses v4, causing the error. installing @better-auth/cli as dev dep in the project works. likely due to bun pm vs npm differences

<!-- gh-comment-id:3205325550 --> @nicognaW commented on GitHub (Aug 20, 2025): i had the same issue with bunx before. checked my bunx dir and found zod at 3.25.0. and i saw here https://github.com/better-auth/better-auth/blob/d921471a742109c8c5c930b8c7aadcf4c40c9ca0/packages/cli/package.json#L67 that @better-auth/cli's peer dep requires "zod": "3.25.0 || ^4.0.0". guessing bun installed the first match 3.25.0, but my project uses v4, causing the error. installing @better-auth/cli as dev dep in the project works. likely due to bun pm vs npm differences
Author
Owner

@Pirulax commented on GitHub (Aug 21, 2025):

I've managed to fix this by installing latest node (not sure if it's a must), and adding zod to my dev deps: yarn add -D zod. Now it works.

<!-- gh-comment-id:3208500429 --> @Pirulax commented on GitHub (Aug 21, 2025): I've managed to fix this by installing latest node (not sure if it's a must), and adding `zod` to my dev deps: `yarn add -D zod`. Now it works.
Author
Owner

@strblr commented on GitHub (Aug 24, 2025):

Same issue, better-auth/cli@1.3.4 worked but only with node 23. Node 24 made it fail as well but with a completely different error (node-gyp related).

<!-- gh-comment-id:3218403556 --> @strblr commented on GitHub (Aug 24, 2025): Same issue, `better-auth/cli@1.3.4` worked but only with node 23. Node 24 made it fail as well but with a completely different error (node-gyp related).
Author
Owner

@himself65 commented on GitHub (Aug 24, 2025):

Same issue, better-auth/cli@1.3.4 worked but only with node 23. Node 24 made it fail as well but with a completely different error (node-gyp related).

node-gyp seems not to be related to better-auth since we don't have that in our code and our deps.

Can you show the error log? Thanks

<!-- gh-comment-id:3218454097 --> @himself65 commented on GitHub (Aug 24, 2025): > Same issue, `better-auth/cli@1.3.4` worked but only with node 23. Node 24 made it fail as well but with a completely different error (node-gyp related). node-gyp seems not to be related to better-auth since we don't have that in our code and our deps. Can you show the error log? Thanks
Author
Owner

@strblr commented on GitHub (Aug 24, 2025):

@himself65 Sure. It happens with better-auth/cli@1.3.4 and Node 24.6.0:

> bun run db:auth:generate
$ bunx @better-auth/cli@1.3.4 generate --config server/utils/auth.ts --output server/db/auth.schema.ts
  ⚙️  @prisma/client [4/4] 
make: Entering directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build'
  TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate
  ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate
  TOUCH Release/obj.target/deps/locate_sqlite3.stamp
  CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o
rm ba23eeee118cd63e16015df367567cb043fed872.intermediate
make: Leaving directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build'

(node:734875) [DEP0176] DeprecationWarning: fs.R_OK is deprecated, use fs.constants.R_OK instead
(Use `node --trace-deprecation ...` to show where the warning was created)
prebuild-install warn install No prebuilt binaries found (target=24.6.0 runtime=node arch=x64 libc= platform=linux)
gyp info it worked if it ends with ok
gyp info using node-gyp@11.4.1
gyp info using node@24.6.0 | linux | x64
gyp info find Python using Python version 3.12.3 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/user/.cache/node-gyp/24.6.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/user/.cache/node-gyp/24.6.0',
gyp info spawn args '-Dnode_gyp_dir=/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/home/user/.cache/node-gyp/24.6.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 32 ]
make: cc: No such file or directory
make: *** [deps/sqlite3.target.mk:200: Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o] Error 127
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.<anonymous> (/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/lib/build.js:219:23)
gyp ERR! System Linux 5.15.167.4-microsoft-standard-WSL2
gyp ERR! command "/home/user/.nvm/versions/node/v24.6.0/bin/node" "/tmp/bunx-1000-node-gyp@latest/node_modules/.bin/node-gyp" "rebuild" "--release"
gyp ERR! cwd /tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3
gyp ERR! node -v v24.6.0
gyp ERR! node-gyp -v v11.4.1
gyp ERR! not ok 

error: install script from "better-sqlite3" exited with 1
error: script "db:auth:generate" exited with code 1
<!-- gh-comment-id:3218461109 --> @strblr commented on GitHub (Aug 24, 2025): @himself65 Sure. It happens with better-auth/cli@1.3.4 and Node 24.6.0: ``` > bun run db:auth:generate $ bunx @better-auth/cli@1.3.4 generate --config server/utils/auth.ts --output server/db/auth.schema.ts ⚙️ @prisma/client [4/4] make: Entering directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build' TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate TOUCH Release/obj.target/deps/locate_sqlite3.stamp CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o rm ba23eeee118cd63e16015df367567cb043fed872.intermediate make: Leaving directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build' (node:734875) [DEP0176] DeprecationWarning: fs.R_OK is deprecated, use fs.constants.R_OK instead (Use `node --trace-deprecation ...` to show where the warning was created) prebuild-install warn install No prebuilt binaries found (target=24.6.0 runtime=node arch=x64 libc= platform=linux) gyp info it worked if it ends with ok gyp info using node-gyp@11.4.1 gyp info using node@24.6.0 | linux | x64 gyp info find Python using Python version 3.12.3 found at "/usr/bin/python3" gyp info spawn /usr/bin/python3 gyp info spawn args [ gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/gyp/gyp_main.py', gyp info spawn args 'binding.gyp', gyp info spawn args '-f', gyp info spawn args 'make', gyp info spawn args '-I', gyp info spawn args '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build/config.gypi', gyp info spawn args '-I', gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/addon.gypi', gyp info spawn args '-I', gyp info spawn args '/home/user/.cache/node-gyp/24.6.0/include/node/common.gypi', gyp info spawn args '-Dlibrary=shared_library', gyp info spawn args '-Dvisibility=default', gyp info spawn args '-Dnode_root_dir=/home/user/.cache/node-gyp/24.6.0', gyp info spawn args '-Dnode_gyp_dir=/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp', gyp info spawn args '-Dnode_lib_file=/home/user/.cache/node-gyp/24.6.0/<(target_arch)/node.lib', gyp info spawn args '-Dmodule_root_dir=/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3', gyp info spawn args '-Dnode_engine=v8', gyp info spawn args '--depth=.', gyp info spawn args '--no-parallel', gyp info spawn args '--generator-output', gyp info spawn args 'build', gyp info spawn args '-Goutput_dir=.' gyp info spawn args ] gyp info spawn make gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 32 ] make: cc: No such file or directory make: *** [deps/sqlite3.target.mk:200: Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o] Error 127 gyp ERR! build error gyp ERR! stack Error: `make` failed with exit code: 2 gyp ERR! stack at ChildProcess.<anonymous> (/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/lib/build.js:219:23) gyp ERR! System Linux 5.15.167.4-microsoft-standard-WSL2 gyp ERR! command "/home/user/.nvm/versions/node/v24.6.0/bin/node" "/tmp/bunx-1000-node-gyp@latest/node_modules/.bin/node-gyp" "rebuild" "--release" gyp ERR! cwd /tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3 gyp ERR! node -v v24.6.0 gyp ERR! node-gyp -v v11.4.1 gyp ERR! not ok error: install script from "better-sqlite3" exited with 1 error: script "db:auth:generate" exited with code 1 ```
Author
Owner

@himself65 commented on GitHub (Aug 24, 2025):

No such file or directory

https://github.com/WiseLibs/better-sqlite3/issues/1326
https://github.com/WiseLibs/better-sqlite3/issues/1330

It is definitely caused by better-sqlite3. I would recommend you clean up the cache and node_modules and try installing again.

<!-- gh-comment-id:3218463090 --> @himself65 commented on GitHub (Aug 24, 2025): > No such file or directory https://github.com/WiseLibs/better-sqlite3/issues/1326 https://github.com/WiseLibs/better-sqlite3/issues/1330 It is definitely caused by `better-sqlite3`. I would recommend you clean up the cache and node_modules and try installing again.
Author
Owner

@strblr commented on GitHub (Aug 24, 2025):

Good catch, thanks! I'll try that later

<!-- gh-comment-id:3218464358 --> @strblr commented on GitHub (Aug 24, 2025): Good catch, thanks! I'll try that later
Author
Owner

@louiejakebell commented on GitHub (Aug 25, 2025):

I was experiencing the same issue related to not being able to find the zod module and took a quick look through the comments here

For me the fix was

  • Using Node v20.19.0 (I don't think this part is necessarily relevant but adding it as details anyhow)
  • Adding zod as a dependency (I do not actually use it in application but temporarily added it for running the script once)
  • Using specifically version 1.3.4 of the CLI as mentioned above (can be achieved directly via npx @better-auth/cli@1.3.4 migrate)
<!-- gh-comment-id:3219751874 --> @louiejakebell commented on GitHub (Aug 25, 2025): I was experiencing the same issue related to not being able to find the `zod` module and took a quick look through the comments here For me the fix was - Using Node `v20.19.0` (I don't think this part is necessarily relevant but adding it as details anyhow) - Adding `zod` as a dependency (I do not actually use it in application but temporarily added it for running the script once) - Using specifically version `1.3.4` of the CLI as mentioned above (can be achieved directly via `npx @better-auth/cli@1.3.4 migrate`)
Author
Owner

@depsimon commented on GitHub (Aug 25, 2025):

Have you installed zod ? and what version is this ?. it is currently peerDep.

Shouldn't it be a devDependency as it breaks the CLI when used with npx/bunx?

I'm not using zod in my project, and I don't want to install it alongside another validation lib

<!-- gh-comment-id:3221448027 --> @depsimon commented on GitHub (Aug 25, 2025): > Have you installed zod ? and what version is this ?. it is currently peerDep. Shouldn't it be a devDependency as it breaks the CLI when used with npx/bunx? I'm not using zod in my project, and I don't want to install it alongside another validation lib
Author
Owner

@himself65 commented on GitHub (Aug 25, 2025):

Thanks for the feedback. We got it fixed in the Canary version. Will release stable soon!

<!-- gh-comment-id:3221775386 --> @himself65 commented on GitHub (Aug 25, 2025): Thanks for the feedback. We got it fixed in the Canary version. Will release stable soon!
Author
Owner

@krisnaw commented on GitHub (Sep 3, 2025):

hi @himself65 Any info on when the fix for this bug will be released?

<!-- gh-comment-id:3247544071 --> @krisnaw commented on GitHub (Sep 3, 2025): hi @himself65 Any info on when the fix for this bug will be released?
Author
Owner

@Bicheka commented on GitHub (Jan 25, 2026):

I was having this issue today where it would be impossible to generate the schema when running bun x @better-auth/cli@latest generate I would get this error:

[#better-auth]: Couldn't read your auth config. Error: Cannot find module 'bun'
Require stack:
- /home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/driver.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1421:15)
    at require.resolve (node:internal/modules/helpers:163:19)
    at jitiResolve (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:148703)
    at jitiRequire (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:150290)
    at import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158307)
    at /home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/driver.js:1:247
    at eval_evalModule (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:155533)
    at /tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:154214
    at async import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301)
    at async /home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/index.js:1:186 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/driver.js'
  ]
}

I was able to generate the schema after many trials with this command:
bunx --bun @better-auth/cli@1.3.4 generate --config ./src/lib/auth.ts

If I change the version or if I remove the --bun or if I remove the --config ./src/lib/auth.ts it stops working.

<!-- gh-comment-id:3796005527 --> @Bicheka commented on GitHub (Jan 25, 2026): I was having this issue today where it would be impossible to generate the schema when running `bun x @better-auth/cli@latest generate` I would get this error: ``` [#better-auth]: Couldn't read your auth config. Error: Cannot find module 'bun' Require stack: - /home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/driver.js at Module._resolveFilename (node:internal/modules/cjs/loader:1421:15) at require.resolve (node:internal/modules/helpers:163:19) at jitiResolve (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:148703) at jitiRequire (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:150290) at import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158307) at /home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/driver.js:1:247 at eval_evalModule (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:155533) at /tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:154214 at async import (/tmp/bunx-1000-@better-auth/cli@latest/node_modules/jiti/dist/jiti.cjs:1:158301) at async /home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/index.js:1:186 { code: 'MODULE_NOT_FOUND', requireStack: [ '/home/bicheka/projects/tudoo/services/auth/node_modules/drizzle-orm/bun-sql/driver.js' ] } ``` **I was able to generate the schema after many trials with this command:** `bunx --bun @better-auth/cli@1.3.4 generate --config ./src/lib/auth.ts` If I change the version or if I remove the --bun or if I remove the --config ./src/lib/auth.ts it stops working.
Author
Owner

@strblr commented on GitHub (Feb 7, 2026):

@himself65 Sure. It happens with better-auth/cli@1.3.4 and Node 24.6.0:

> bun run db:auth:generate
$ bunx @better-auth/cli generate --config server/utils/auth.ts --output server/db/auth.schema.ts
  ⚙️  @prisma/client [4/4] 
make: Entering directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build'
  TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate
  ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate
  TOUCH Release/obj.target/deps/locate_sqlite3.stamp
  CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o
rm ba23eeee118cd63e16015df367567cb043fed872.intermediate
make: Leaving directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build'

(node:734875) [DEP0176] DeprecationWarning: fs.R_OK is deprecated, use fs.constants.R_OK instead
(Use `node --trace-deprecation ...` to show where the warning was created)
prebuild-install warn install No prebuilt binaries found (target=24.6.0 runtime=node arch=x64 libc= platform=linux)
gyp info it worked if it ends with ok
gyp info using node-gyp@11.4.1
gyp info using node@24.6.0 | linux | x64
gyp info find Python using Python version 3.12.3 found at "/usr/bin/python3"
gyp info spawn /usr/bin/python3
gyp info spawn args [
gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args 'binding.gyp',
gyp info spawn args '-f',
gyp info spawn args 'make',
gyp info spawn args '-I',
gyp info spawn args '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build/config.gypi',
gyp info spawn args '-I',
gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/addon.gypi',
gyp info spawn args '-I',
gyp info spawn args '/home/user/.cache/node-gyp/24.6.0/include/node/common.gypi',
gyp info spawn args '-Dlibrary=shared_library',
gyp info spawn args '-Dvisibility=default',
gyp info spawn args '-Dnode_root_dir=/home/user/.cache/node-gyp/24.6.0',
gyp info spawn args '-Dnode_gyp_dir=/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp',
gyp info spawn args '-Dnode_lib_file=/home/user/.cache/node-gyp/24.6.0/<(target_arch)/node.lib',
gyp info spawn args '-Dmodule_root_dir=/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3',
gyp info spawn args '-Dnode_engine=v8',
gyp info spawn args '--depth=.',
gyp info spawn args '--no-parallel',
gyp info spawn args '--generator-output',
gyp info spawn args 'build',
gyp info spawn args '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 32 ]
make: cc: No such file or directory
make: *** [deps/sqlite3.target.mk:200: Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o] Error 127
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.<anonymous> (/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/lib/build.js:219:23)
gyp ERR! System Linux 5.15.167.4-microsoft-standard-WSL2
gyp ERR! command "/home/user/.nvm/versions/node/v24.6.0/bin/node" "/tmp/bunx-1000-node-gyp@latest/node_modules/.bin/node-gyp" "rebuild" "--release"
gyp ERR! cwd /tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3
gyp ERR! node -v v24.6.0
gyp ERR! node-gyp -v v11.4.1
gyp ERR! not ok 

error: install script from "better-sqlite3" exited with 1
error: script "db:auth:generate" exited with code 1

For anyone encountering this, fixed it with:

sudo apt update && sudo apt install -y build-essential
<!-- gh-comment-id:3864185952 --> @strblr commented on GitHub (Feb 7, 2026): > [@himself65](https://github.com/himself65) Sure. It happens with better-auth/cli@1.3.4 and Node 24.6.0: > > ``` > > bun run db:auth:generate > $ bunx @better-auth/cli generate --config server/utils/auth.ts --output server/db/auth.schema.ts > ⚙️ @prisma/client [4/4] > make: Entering directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build' > TOUCH ba23eeee118cd63e16015df367567cb043fed872.intermediate > ACTION deps_sqlite3_gyp_locate_sqlite3_target_copy_builtin_sqlite3 ba23eeee118cd63e16015df367567cb043fed872.intermediate > TOUCH Release/obj.target/deps/locate_sqlite3.stamp > CC(target) Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o > rm ba23eeee118cd63e16015df367567cb043fed872.intermediate > make: Leaving directory '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build' > > (node:734875) [DEP0176] DeprecationWarning: fs.R_OK is deprecated, use fs.constants.R_OK instead > (Use `node --trace-deprecation ...` to show where the warning was created) > prebuild-install warn install No prebuilt binaries found (target=24.6.0 runtime=node arch=x64 libc= platform=linux) > gyp info it worked if it ends with ok > gyp info using node-gyp@11.4.1 > gyp info using node@24.6.0 | linux | x64 > gyp info find Python using Python version 3.12.3 found at "/usr/bin/python3" > gyp info spawn /usr/bin/python3 > gyp info spawn args [ > gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/gyp/gyp_main.py', > gyp info spawn args 'binding.gyp', > gyp info spawn args '-f', > gyp info spawn args 'make', > gyp info spawn args '-I', > gyp info spawn args '/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3/build/config.gypi', > gyp info spawn args '-I', > gyp info spawn args '/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/addon.gypi', > gyp info spawn args '-I', > gyp info spawn args '/home/user/.cache/node-gyp/24.6.0/include/node/common.gypi', > gyp info spawn args '-Dlibrary=shared_library', > gyp info spawn args '-Dvisibility=default', > gyp info spawn args '-Dnode_root_dir=/home/user/.cache/node-gyp/24.6.0', > gyp info spawn args '-Dnode_gyp_dir=/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp', > gyp info spawn args '-Dnode_lib_file=/home/user/.cache/node-gyp/24.6.0/<(target_arch)/node.lib', > gyp info spawn args '-Dmodule_root_dir=/tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3', > gyp info spawn args '-Dnode_engine=v8', > gyp info spawn args '--depth=.', > gyp info spawn args '--no-parallel', > gyp info spawn args '--generator-output', > gyp info spawn args 'build', > gyp info spawn args '-Goutput_dir=.' > gyp info spawn args ] > gyp info spawn make > gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build', '--jobs', 32 ] > make: cc: No such file or directory > make: *** [deps/sqlite3.target.mk:200: Release/obj.target/sqlite3/gen/sqlite3/sqlite3.o] Error 127 > gyp ERR! build error > gyp ERR! stack Error: `make` failed with exit code: 2 > gyp ERR! stack at ChildProcess.<anonymous> (/tmp/bunx-1000-node-gyp@latest/node_modules/node-gyp/lib/build.js:219:23) > gyp ERR! System Linux 5.15.167.4-microsoft-standard-WSL2 > gyp ERR! command "/home/user/.nvm/versions/node/v24.6.0/bin/node" "/tmp/bunx-1000-node-gyp@latest/node_modules/.bin/node-gyp" "rebuild" "--release" > gyp ERR! cwd /tmp/bunx-1000-@better-auth/cli@1.3.4/node_modules/better-sqlite3 > gyp ERR! node -v v24.6.0 > gyp ERR! node-gyp -v v11.4.1 > gyp ERR! not ok > > error: install script from "better-sqlite3" exited with 1 > error: script "db:auth:generate" exited with code 1 > ``` For anyone encountering this, fixed it with: ``` sudo apt update && sudo apt install -y build-essential ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18404