Better auth schema generation does not work with latest version of Elysia #2160

Closed
opened 2026-03-13 09:31:10 -05:00 by GiteaMirror · 2 comments
Owner

Originally created by @subhaneetshrestha on GitHub (Oct 21, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

  1. Setup better-auth with Elysia config and drizzle ORM.
  2. Try to generate the schema with bunx @better-auth/cli@latest generate

Current vs. Expected behavior

Currently I am getting 2025-10-21T05:00:33.118Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'memoirist' imported from /home/hyzii/Projects/my-hr/node_modules/elysia/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' }

where as I expected this to generate the auth-schema.ts file for drizzle schema.

What version of Better Auth are you using?

1.3.28

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025",
    "release": "6.6.87.2-microsoft-standard-WSL2",
    "cpuCount": 16,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-1260P",
    "totalMemory": "7.61 GB",
    "freeMemory": "5.33 GB"
  },
  "node": {
    "version": "v22.18.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "pg",
      "version": "^8.16.3"
    },
    {
      "name": "drizzle",
      "version": "^0.44.6"
    }
  ],
  "betterAuth": {
    "version": "^1.3.28",
    "config": {
      "plugins": [
        {
          "name": "email-otp",
          "config": {
            "id": "email-otp",
            "endpoints": {},
            "hooks": {
              "after": [
                {}
              ]
            },
            "$ERROR_CODES": {
              "OTP_EXPIRED": "otp expired",
              "INVALID_OTP": "Invalid OTP",
              "INVALID_EMAIL": "Invalid email",
              "USER_NOT_FOUND": "User not found",
              "TOO_MANY_ATTEMPTS": "Too many attempts"
            },
            "rateLimit": [
              {
                "window": 60,
                "max": 3
              },
              {
                "window": 60,
                "max": 3
              },
              {
                "window": 60,
                "max": 3
              },
              {
                "window": 60,
                "max": 3
              }
            ]
          }
        },
        {
          "name": "haveIBeenPwned",
          "config": {
            "id": "haveIBeenPwned",
            "$ERROR_CODES": {
              "PASSWORD_COMPROMISED": "The password you entered has been compromised. Please choose a different password."
            }
          }
        }
      ],
      "emailAndPassword": {
        "enabled": true
      }
    }
  }
}

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

Other

Auth config (if applicable)

import { db } from "@db/index";

import { betterAuth } from "better-auth";
import { drizzleAdapter } from "better-auth/adapters/drizzle";
import Elysia from "elysia";

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

export const betterAuthHandler = new Elysia({
    name: "better-auth",
})
    .mount(auth.handler)
    .macro({
        auth: {
            async resolve({ status, request: { headers } }) {
                const session = await auth.api.getSession({ headers });
                if (!session) return status(401);
                return {
                    user: session.user,
                    session: session.user,
                };
            },
        },
    });

Additional context

This works with Elysia version: 1.4.9 so the latest changes in ELysia broke this.

Originally created by @subhaneetshrestha on GitHub (Oct 21, 2025). ### Is this suited for github? - [ ] Yes, this is suited for github ### To Reproduce 1. Setup better-auth with Elysia config and drizzle ORM. 2. Try to generate the schema with `bunx @better-auth/cli@latest generate` ### Current vs. Expected behavior Currently I am getting `2025-10-21T05:00:33.118Z ERROR [Better Auth]: [#better-auth]: Couldn't read your auth config. Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'memoirist' imported from /home/hyzii/Projects/my-hr/node_modules/elysia/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' }` where as I expected this to generate the auth-schema.ts file for drizzle schema. ### What version of Better Auth are you using? 1.3.28 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025", "release": "6.6.87.2-microsoft-standard-WSL2", "cpuCount": 16, "cpuModel": "12th Gen Intel(R) Core(TM) i7-1260P", "totalMemory": "7.61 GB", "freeMemory": "5.33 GB" }, "node": { "version": "v22.18.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": null, "databases": [ { "name": "pg", "version": "^8.16.3" }, { "name": "drizzle", "version": "^0.44.6" } ], "betterAuth": { "version": "^1.3.28", "config": { "plugins": [ { "name": "email-otp", "config": { "id": "email-otp", "endpoints": {}, "hooks": { "after": [ {} ] }, "$ERROR_CODES": { "OTP_EXPIRED": "otp expired", "INVALID_OTP": "Invalid OTP", "INVALID_EMAIL": "Invalid email", "USER_NOT_FOUND": "User not found", "TOO_MANY_ATTEMPTS": "Too many attempts" }, "rateLimit": [ { "window": 60, "max": 3 }, { "window": 60, "max": 3 }, { "window": 60, "max": 3 }, { "window": 60, "max": 3 } ] } }, { "name": "haveIBeenPwned", "config": { "id": "haveIBeenPwned", "$ERROR_CODES": { "PASSWORD_COMPROMISED": "The password you entered has been compromised. Please choose a different password." } } } ], "emailAndPassword": { "enabled": true } } } } ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript import { db } from "@db/index"; import { betterAuth } from "better-auth"; import { drizzleAdapter } from "better-auth/adapters/drizzle"; import Elysia from "elysia"; export const auth = betterAuth({ database: drizzleAdapter(db, { provider: "pg", usePlural: true, }), emailAndPassword: { enabled: true, }, }); export const betterAuthHandler = new Elysia({ name: "better-auth", }) .mount(auth.handler) .macro({ auth: { async resolve({ status, request: { headers } }) { const session = await auth.api.getSession({ headers }); if (!session) return status(401); return { user: session.user, session: session.user, }; }, }, }); ``` ### Additional context This works with Elysia version: 1.4.9 so the latest changes in ELysia broke this.
GiteaMirror added the elysia label 2026-03-13 09:31:10 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 21, 2025):

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

This is suited for GitHub—it's a compatibility issue between Better Auth and the latest Elysia version. The error happens because Elysia now expects the memoirist package to be present, but it's not automatically installed, so Better Auth CLI fails when importing your config that uses Elysia. This wasn't an issue with Elysia 1.4.9, so it's likely a new dependency or breaking change in Elysia after that version.

You can try installing memoirist manually with npm install memoirist (or your package manager of choice). If that doesn't resolve it, you may need to temporarily use Elysia 1.4.9 until Better Auth updates its integration logic for newer Elysia versions. This pattern matches other module resolution errors seen with Better Auth CLI and changing framework dependencies, where manually installing missing peer dependencies or downgrading versions has worked as a workaround [example issue].

If manual installation works, mention it in your report. If not, include the error and your environment details—this will help maintainers track and fix the breaking change.

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 (Oct 21, 2025): <!-- Greeting --> Hi @subhaneetshrestha! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is suited for GitHub—it's a compatibility issue between Better Auth and the latest Elysia version. The error happens because Elysia now expects the `memoirist` package to be present, but it's not automatically installed, so Better Auth CLI fails when importing your config that uses Elysia. This wasn't an issue with Elysia 1.4.9, so it's likely a new dependency or breaking change in Elysia after that version. You can try installing `memoirist` manually with `npm install memoirist` (or your package manager of choice). If that doesn't resolve it, you may need to temporarily use Elysia 1.4.9 until Better Auth updates its integration logic for newer Elysia versions. This pattern matches other module resolution errors seen with Better Auth CLI and changing framework dependencies, where manually installing missing peer dependencies or downgrading versions has worked as a workaround [[example issue](https://github.com/better-auth/better-auth/issues/3951)]. If manual installation works, mention it in your report. If not, include the error and your environment details—this will help maintainers track and fix the breaking change. <!-- 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/cf426b43-d4e9-463d-a075-8d20b419ca40?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/cf426b43-d4e9-463d-a075-8d20b419ca40?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/cf426b43-d4e9-463d-a075-8d20b419ca40?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/cf426b43-d4e9-463d-a075-8d20b419ca40?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/cf426b43-d4e9-463d-a075-8d20b419ca40?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/cf426b43-d4e9-463d-a075-8d20b419ca40?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/cf426b43-d4e9-463d-a075-8d20b419ca40?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/5446)
Author
Owner

@subhaneetshrestha commented on GitHub (Oct 21, 2025):

I am using Elysia version 1.4.9 for now and works without any issue.

@subhaneetshrestha commented on GitHub (Oct 21, 2025): I am using Elysia version 1.4.9 for now and works without any issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2160