TypeError: adapter.createSchema(...).then is not a function when using native Cloudflare D1 binding #3026

Closed
opened 2026-03-13 10:35:08 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @plabew on GitHub (Mar 10, 2026).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Set up better-auth with a Cloudflare D1 binding:
import { betterAuth } from "better-auth";
import { env } from "cloudflare:workers";

export const auth = betterAuth({
  database: env.DB, 
});
  1. Run bun x auth@latest generate
  2. See error: TypeError: adapter.createSchema(...).then is not a function

Current vs. Expected behavior

The CLI should generate the sqlite compatible migrations file.

What version of Better Auth are you using?

1.5.4

System info

{
  "system": {
    "platform": "darwin",
    "arch": "arm64",
    "version": "Darwin Kernel Version 25.3.0: Wed Jan 28 20:49:24 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T8132",
    "release": "25.3.0",
    "cpuCount": 10,
    "cpuModel": "Apple M4",
    "totalMemory": "16.00 GB",
    "freeMemory": "3.67 GB"
  },
  "node": {
    "version": "v25.8.0",
    "env": "development"
  },
  "packageManager": {
    "name": "bun",
    "version": "1.3.10"
  },
  "frameworks": [
    {
      "name": "hono",
      "version": "^4.12.7"
    }
  ],
  "databases": [
    {
      "name": "better-sqlite3",
      "version": "^12.6.2"
    },
    {
      "name": "drizzle",
      "version": "^0.44.7"
    }
  ],
  "betterAuth": {
    "version": "^1.5.4",
    "config": {}
  }
}

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

Backend

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { env } from "cloudflare:workers";
export const auth = betterAuth({
  database: env.DB, 
});

Additional context

No response

Originally created by @plabew on GitHub (Mar 10, 2026). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce 1. Set up `better-auth` with a Cloudflare D1 binding: ```typescript import { betterAuth } from "better-auth"; import { env } from "cloudflare:workers"; export const auth = betterAuth({ database: env.DB, }); ``` 2. Run `bun x auth@latest generate` 3. See error: `TypeError: adapter.createSchema(...).then is not a function` ### Current vs. Expected behavior The CLI should generate the sqlite compatible migrations file. ### What version of Better Auth are you using? 1.5.4 ### System info ```bash { "system": { "platform": "darwin", "arch": "arm64", "version": "Darwin Kernel Version 25.3.0: Wed Jan 28 20:49:24 PST 2026; root:xnu-12377.81.4~5/RELEASE_ARM64_T8132", "release": "25.3.0", "cpuCount": 10, "cpuModel": "Apple M4", "totalMemory": "16.00 GB", "freeMemory": "3.67 GB" }, "node": { "version": "v25.8.0", "env": "development" }, "packageManager": { "name": "bun", "version": "1.3.10" }, "frameworks": [ { "name": "hono", "version": "^4.12.7" } ], "databases": [ { "name": "better-sqlite3", "version": "^12.6.2" }, { "name": "drizzle", "version": "^0.44.7" } ], "betterAuth": { "version": "^1.5.4", "config": {} } } ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { env } from "cloudflare:workers"; export const auth = betterAuth({ database: env.DB, }); ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 10:35:08 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Mar 10, 2026):

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

The issue is that the CLI cannot access Cloudflare D1 bindings like env.DB because they're only available within the Workers runtime request context — not during local CLI execution.

While Better Auth 1.5+ supports native D1 bindings for runtime use, the generate command runs locally and can't resolve env.DB.

Workaround: For schema generation, temporarily configure a local SQLite database (like better-sqlite3) in your auth config when running CLI commands, or use Drizzle ORM which has its own migration tooling that works independently:

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import { drizzle } from "drizzle-orm/d1";

export const auth = betterAuth({
  database: drizzleAdapter(drizzle(env.DB), {
    provider: "sqlite",
  }),
});

Then you can use drizzle-kit generate for migrations instead of the Better Auth CLI.

See this discussion for more context on D1 binding limitations with CLI tooling.

To reply, just mention @dosu.


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

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Mar 10, 2026): <!-- Greeting --> Hi @plabew! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The issue is that the **CLI cannot access Cloudflare D1 bindings** like `env.DB` because they're only available within the Workers runtime request context — not during local CLI execution. While [Better Auth 1.5+ supports native D1 bindings](https://better-auth.com/blog/1-5#cloudflare-d1-support) for runtime use, the `generate` command runs locally and can't resolve `env.DB`. **Workaround**: For schema generation, temporarily configure a local SQLite database (like `better-sqlite3`) in your auth config when running CLI commands, or use Drizzle ORM which has its own migration tooling that works independently: ```typescript import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import { drizzle } from "drizzle-orm/d1"; export const auth = betterAuth({ database: drizzleAdapter(drizzle(env.DB), { provider: "sqlite", }), }); ``` Then you can use `drizzle-kit generate` for migrations instead of the Better Auth CLI. See [this discussion](https://github.com/better-auth/better-auth/discussions/7487#discussioncomment-15546007) for more context on D1 binding limitations with CLI tooling. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=brand-link).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=great_response&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=irrelevant_answer&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=incorrect_sources&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=too_verbose&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=hallucination&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=bug_report&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-bug_report) | [Other](https://app.dosu.dev/response-feedback/f3d1c3f0-b86b-455c-ac99-9180937ac515?feedback_type=other&utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=feedback-other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=chat-badge)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20issue%20is%20that%20the%20%2A%2ACLI%20cannot%20access%20Cloudflare%20D1%20bindings%2A%2A%20like%20%60env.DB%60%20because%20they%27re%20only%20available%20within%20the%20Workers%20runtime%20request%20context%20%E2%80%94%20not%20during%20local%20CLI%20execution.%0A%0AWhile%20%5BBetter%20Auth%201.5%2B%20supports%20native%20D1%20bindings%5D%28https%3A//better-auth.com/blog/1-5%23cloudflare-d1-support%29%20for%20runtime%20use%2C%20the%20%60generate%60%20command%20runs%20locally%20and%20can%27t%20resolve%20%60env.DB%60.%0A%0A%2A%2AWorkaround%2A%2A%3A%20For%20schema%20generation%2C%20temporarily%20configure%20a%20local%20SQLite%20database%20%28like%20%60better-sqlite3%60%29%20in%20your%20auth%20config%20when%20running%20CLI%20commands%2C%20or%20use%20Drizzle%20ORM%20which%20has%20its%20own%20migration%20tooling%20that%20works%20independently%3A%0A%0A%60%60%60typescript%0Aimport%20%7B%20betterAuth%20%7D%20from%20%22better-auth%22%3B%0Aimport%20%7B%20drizzleAdapter%20%7D%20from%20%22better-auth/adapters/drizzle%22%3B%0Aimport%20%7B%20drizzle%20%7D%20from%20%22drizzle-orm/d1%22%3B%0A%0Aexport%20const%20auth%20%3D%20betterAuth%28%7B%0A%20%20database%3A%20drizzleAdapter%28drizzle%28env.DB%29%2C%20%7B%0A%20%20%20%20provider%3A%20%22sqlite%22%2C%0A%20%20%7D%29%2C%0A%7D%29%3B%0A%60%60%60%0A%0AThen%20you%20can%20use%20%60drizzle-kit%20generate%60%20for%20migrations%20instead%20of%20the%20Better%20Auth%20CLI.%0A%0ASee%20%5Bthis%20discussion%5D%28https%3A//github.com/better-auth/better-auth/discussions/7487%23discussioncomment-15546007%29%20for%20more%20context%20on%20D1%20binding%20limitations%20with%20CLI%20tooling.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot?utm_source=github&utm_medium=bot-comment&utm_campaign=github-assistant&utm_content=join-discord)&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/8537)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#3026