[CLI] generate command fails with SyntaxError on better-auth/db imports (versions 1.4.6–1.4.20+) #2946

Closed
opened 2026-03-13 10:29:18 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @chandikajayaweera on GitHub (Mar 1, 2026).

Originally assigned to: @himself65 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

A minimal reproduction repo is available here: https://github.com/chandikajayaweera/bug_report

  1. Create a SvelteKit project with better-auth installed
  2. Run the schema generation CLI:
    pnpm dlx @better-auth/cli@1.4.20 generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes
    
  3. The command crashes immediately with a SyntaxError (see below)
  4. To confirm the regression, run the same command with @1.4.5 — it succeeds

Current vs. Expected behavior

Current behavior:

The CLI crashes on startup with a SyntaxError because it tries to import named exports (getAdapter, getMigrations) from better-auth/db that don't exist in the installed package.

CLI versions 1.4.141.4.20+:

import { getAuthTables, getMigrations } from "better-auth/db";
                        ^^^^^^^^^^^^^
SyntaxError: The requested module 'better-auth/db' does not provide an export named 'getMigrations'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:226:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:335:5)
Node.js v22.21.0

CLI versions 1.4.61.4.13:

import { getAdapter, getAuthTables, getMigrations } from "better-auth/db";
         ^^^^^^^^^^
SyntaxError: The requested module 'better-auth/db' does not provide an export named 'getAdapter'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:226:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:335:5)
Node.js v22.21.0
CLI Version Result Missing export
1.4.5 Works
1.4.61.4.13 Fails getAdapter
1.4.141.4.20+ Fails getMigrations

Expected behavior:

@better-auth/cli generate produces a valid schema file without errors, as it did in version 1.4.5.

Workaround (until fixed):

Pin the CLI to 1.4.5:

pnpm dlx @better-auth/cli@1.4.5 generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes

What version of Better Auth are you using?

1.4.18

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.26200",
    "cpuCount": 12,
    "cpuModel": "AMD Ryzen 5 5600X 6-Core Processor             ",
    "totalMemory": "15.93 GB",
    "freeMemory": "4.75 GB"
  },
  "node": {
    "version": "v22.21.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.4"
  },
  "frameworks": [
    {
      "name": "svelte",
      "version": "^5.51.0"
    },
    {
      "name": "@sveltejs/kit",
      "version": "^2.50.2"
    }
  ],
  "databases": [
    {
      "name": "@libsql/client",
      "version": "^0.17.0"
    },
    {
      "name": "drizzle",
      "version": "^0.45.1"
    }
  ],
  "betterAuth": {
    "version": "^1.4.18",
    "config": {
      "baseURL": "http://localhost:5173",
      "secret": "[REDACTED]",
      "emailAndPassword": {
        "enabled": true
      },
      "plugins": [
        {
          "name": "sveltekit-cookies",
          "config": {
            "id": "sveltekit-cookies",
            "hooks": {
              "after": [
                {}
              ]
            }
          }
        }
      ]
    }
  }
}

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

Package

Auth config (if applicable)

import { betterAuth } from 'better-auth/minimal';
import { drizzleAdapter } from 'better-auth/adapters/drizzle';
import { sveltekitCookies } from 'better-auth/svelte-kit';
import { env } from '$env/dynamic/private';
import { getRequestEvent } from '$app/server';
import { db } from '$lib/server/db';

export const auth = betterAuth({
	baseURL: env.ORIGIN,
	secret: env.BETTER_AUTH_SECRET,
	database: drizzleAdapter(db, { provider: 'sqlite' }),
	emailAndPassword: { enabled: true },
	plugins: [sveltekitCookies(getRequestEvent)]
});

Additional context

This issue affects all projects using the CLI via npx or pnpm dlx, since those tools always fetch the latest CLI version regardless of the locally installed better-auth version. The breakage appears to have started at 1.4.6 with the removal/move of getAdapter from better-auth/db, and changed again at 1.4.14 where getMigrations also disappeared from the same export path.

Tested on Windows 11, Node.js v22.21.0, pnpm v10.19.0.

Originally created by @chandikajayaweera on GitHub (Mar 1, 2026). Originally assigned to: @himself65 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce A minimal reproduction repo is available here: **https://github.com/chandikajayaweera/bug_report** 1. Create a SvelteKit project with `better-auth` installed 2. Run the schema generation CLI: ```sh pnpm dlx @better-auth/cli@1.4.20 generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes ``` 3. The command crashes immediately with a `SyntaxError` (see below) 4. To confirm the regression, run the same command with `@1.4.5` — it succeeds ### Current vs. Expected behavior **Current behavior:** The CLI crashes on startup with a `SyntaxError` because it tries to import named exports (`getAdapter`, `getMigrations`) from `better-auth/db` that don't exist in the installed package. CLI versions `1.4.14` – `1.4.20+`: ``` import { getAuthTables, getMigrations } from "better-auth/db"; ^^^^^^^^^^^^^ SyntaxError: The requested module 'better-auth/db' does not provide an export named 'getMigrations' at ModuleJob._instantiate (node:internal/modules/esm/module_job:226:21) at async ModuleJob.run (node:internal/modules/esm/module_job:335:5) Node.js v22.21.0 ``` CLI versions `1.4.6` – `1.4.13`: ``` import { getAdapter, getAuthTables, getMigrations } from "better-auth/db"; ^^^^^^^^^^ SyntaxError: The requested module 'better-auth/db' does not provide an export named 'getAdapter' at ModuleJob._instantiate (node:internal/modules/esm/module_job:226:21) at async ModuleJob.run (node:internal/modules/esm/module_job:335:5) Node.js v22.21.0 ``` | CLI Version | Result | Missing export | |---|---|---| | `1.4.5` | ✅ Works | — | | `1.4.6` – `1.4.13` | ❌ Fails | `getAdapter` | | `1.4.14` – `1.4.20+` | ❌ Fails | `getMigrations` | **Expected behavior:** `@better-auth/cli generate` produces a valid schema file without errors, as it did in version `1.4.5`. **Workaround (until fixed):** Pin the CLI to `1.4.5`: ```sh pnpm dlx @better-auth/cli@1.4.5 generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes ``` --- ### What version of Better Auth are you using? 1.4.18 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.26200", "cpuCount": 12, "cpuModel": "AMD Ryzen 5 5600X 6-Core Processor ", "totalMemory": "15.93 GB", "freeMemory": "4.75 GB" }, "node": { "version": "v22.21.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.4" }, "frameworks": [ { "name": "svelte", "version": "^5.51.0" }, { "name": "@sveltejs/kit", "version": "^2.50.2" } ], "databases": [ { "name": "@libsql/client", "version": "^0.17.0" }, { "name": "drizzle", "version": "^0.45.1" } ], "betterAuth": { "version": "^1.4.18", "config": { "baseURL": "http://localhost:5173", "secret": "[REDACTED]", "emailAndPassword": { "enabled": true }, "plugins": [ { "name": "sveltekit-cookies", "config": { "id": "sveltekit-cookies", "hooks": { "after": [ {} ] } } } ] } } } ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from 'better-auth/minimal'; import { drizzleAdapter } from 'better-auth/adapters/drizzle'; import { sveltekitCookies } from 'better-auth/svelte-kit'; import { env } from '$env/dynamic/private'; import { getRequestEvent } from '$app/server'; import { db } from '$lib/server/db'; export const auth = betterAuth({ baseURL: env.ORIGIN, secret: env.BETTER_AUTH_SECRET, database: drizzleAdapter(db, { provider: 'sqlite' }), emailAndPassword: { enabled: true }, plugins: [sveltekitCookies(getRequestEvent)] }); ``` ### Additional context This issue affects **all projects** using the CLI via `npx` or `pnpm dlx`, since those tools always fetch the latest CLI version regardless of the locally installed `better-auth` version. The breakage appears to have started at `1.4.6` with the removal/move of `getAdapter` from `better-auth/db`, and changed again at `1.4.14` where `getMigrations` also disappeared from the same export path. Tested on Windows 11, Node.js v22.21.0, pnpm v10.19.0.
GiteaMirror added the bug label 2026-03-13 10:29:18 -05:00
Author
Owner

@FizanMuhammedFaisal commented on GitHub (Mar 1, 2026):

I'm experiencing this exact same issue too.

@FizanMuhammedFaisal commented on GitHub (Mar 1, 2026): I'm experiencing this exact same issue too.
Author
Owner

@himself65 commented on GitHub (Mar 1, 2026):

Please use pnpm dlx auth generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes now.

For the issue you mentioned, I think cli links to the latest 1.4 better-auth, which doesn't include the API The workaround is to install cli to devDeps and overwrite the version to exact version

@himself65 commented on GitHub (Mar 1, 2026): Please use `pnpm dlx auth generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes` now. For the issue you mentioned, I think cli links to the latest 1.4 better-auth, which doesn't include the API The workaround is to install cli to devDeps and overwrite the version to exact version
Author
Owner

@himself65 commented on GitHub (Mar 1, 2026):

I will give a small patch for it.

@himself65 commented on GitHub (Mar 1, 2026): I will give a small patch for it.
Author
Owner

@himself65 commented on GitHub (Mar 1, 2026):

pnpm dlx @better-auth/cli@1.4.21 generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes

@himself65 commented on GitHub (Mar 1, 2026): `pnpm dlx @better-auth/cli@1.4.21 generate --config src/lib/server/auth.ts --output src/lib/server/db/auth.schema.ts --yes`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2946