[GH-ISSUE #5702] Cannot find package 'mongodb' imported from better-auth\dist\test-utils\index.mjs #10331

Closed
opened 2026-04-13 06:23:35 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @astrodomas on GitHub (Oct 31, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/5702

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

// myTest.test.ts
import { getTestInstanceMemory } from "better-auth/test";

describe('my-test', async () => {
  const testClient = await getTestInstanceMemory(
    {
      ...authConfig,
      emailAndPassword: {
        ...authConfig.emailAndPassword,
        requireEmailVerification: false,
      },
    },
    {
      testWith: "memory",
      disableTestUser: true,
    }
  );
})

Current vs. Expected behavior

When using better-auths test utility and specifying to test with memory, mongodb is still required as a dependency even though the configuration uses:

...
import { prismaAdapter } from "better-auth/adapters/prisma";

const authconfig = {
...
  database: prismaAdapter(prisma, {
    provider: "postgresql",
  }),
...
} satisfies Parameters<typeof betterAuth>[0]

export const auth = betterAuth(authConfig)

What version of Better Auth are you using?

1.3.34

System info

"system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Pro",
    "release": "10.0.22621",
    "cpuCount": 16,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-1260P",
    "totalMemory": "31.70 GB",
    "freeMemory": "15.93 GB"
  },
  "node": {
    "version": "v22.20.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.3"
  },
  "frameworks": [
    {
      "name": "express",
      "version": "^5.1.0"
    }
  ],
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.16.2"
    }
  ]

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

Other

Auth config (if applicable)


Additional context

This affects only the test utilities.

Originally created by @astrodomas on GitHub (Oct 31, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/5702 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce ```typescript // myTest.test.ts import { getTestInstanceMemory } from "better-auth/test"; describe('my-test', async () => { const testClient = await getTestInstanceMemory( { ...authConfig, emailAndPassword: { ...authConfig.emailAndPassword, requireEmailVerification: false, }, }, { testWith: "memory", disableTestUser: true, } ); }) ``` ### Current vs. Expected behavior When using better-auths test utility and specifying to test with memory, `mongodb` is still required as a dependency even though the configuration uses: ```typescript ... import { prismaAdapter } from "better-auth/adapters/prisma"; const authconfig = { ... database: prismaAdapter(prisma, { provider: "postgresql", }), ... } satisfies Parameters<typeof betterAuth>[0] export const auth = betterAuth(authConfig) ``` ### What version of Better Auth are you using? 1.3.34 ### System info ```bash "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Pro", "release": "10.0.22621", "cpuCount": 16, "cpuModel": "12th Gen Intel(R) Core(TM) i7-1260P", "totalMemory": "31.70 GB", "freeMemory": "15.93 GB" }, "node": { "version": "v22.20.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.3" }, "frameworks": [ { "name": "express", "version": "^5.1.0" } ], "databases": [ { "name": "@prisma/client", "version": "^6.16.2" } ] ``` ### Which area(s) are affected? (Select all that apply) Other ### Auth config (if applicable) ```typescript ``` ### Additional context This affects only the test utilities.
GiteaMirror added the lockedbug labels 2026-04-13 06:23:35 -05:00
Author
Owner

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

It appears that even when you configure Better Auth to use another adapter (such as Prisma for PostgreSQL), the test utility still tries to import the “mongodb” package. This is likely because the test utilities aren’t fully decoupled from MongoDB–they’re written to support memory or MongoDB-backed tests unconditionally. For a workaround, you can add “mongodb” as a dev dependency (for example, via npm install mongodb --save-dev) so the test runs without the import error. If you’re not planning to test any MongoDB-related functionality, this extra dependency shouldn’t affect your production code. If installing mongodb isn’t ideal or you believe the test utilities should not require it when using a different database, consider filing an issue with the Better Auth maintainers so they can address the conditional import in future releases [1].

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3473201694 --> @better-auth-agent[bot] commented on GitHub (Oct 31, 2025): It appears that even when you configure Better Auth to use another adapter (such as Prisma for PostgreSQL), the test utility still tries to import the “mongodb” package. This is likely because the test utilities aren’t fully decoupled from MongoDB–they’re written to support memory or MongoDB-backed tests unconditionally. For a workaround, you can add “mongodb” as a dev dependency (for example, via npm install mongodb --save-dev) so the test runs without the import error. If you’re not planning to test any MongoDB-related functionality, this extra dependency shouldn’t affect your production code. If installing mongodb isn’t ideal or you believe the test utilities should not require it when using a different database, consider filing an issue with the Better Auth maintainers so they can address the conditional import in future releases [[1]](https://github.com/better-auth/better-auth/issues/4869). <!-- 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)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#10331