APIError (from better-call) is not exported at runtime from better-auth, typings suggest otherwise #701

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

Originally created by @astahmer on GitHub (Feb 18, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

import { APIError } from "better-auth";

leads to

file:///Users/astahmer/dev/alex/emisoup/packages/backend/src/auth/auth.organization.invitation-only.plugin.ts:2
import { APIError } from "better-auth";
         ^^^^^^^^
SyntaxError: The requested module 'better-auth' does not provide an export named 'APIError'
    at ModuleJob._instantiate (node:internal/modules/esm/module_job:177:21)
    at async ModuleJob.run (node:internal/modules/esm/module_job:260:5)
    at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26)
    at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5)

can be fixed with import { APIError } from "better-auth/api";

Current vs. Expected behavior

the type probably shouldnt be exported (or the runtime should be?)


I'm guessing this could be an issue for more than APIError, as I noticed this line export * from 'better-call'; in better-auth/dist/index.d.ts

same issue with import { z } from "better-auth"; (TS is fine with this) due to export * from 'zod'; also in better-auth/dist/index.d.ts

What version of Better Auth are you using?

1.1.17

Provide environment information

Node.js v22.11.0

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

Backend

Auth config (if applicable)


Additional context

No response

Originally created by @astahmer on GitHub (Feb 18, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce `import { APIError } from "better-auth";` leads to ```sh file:///Users/astahmer/dev/alex/emisoup/packages/backend/src/auth/auth.organization.invitation-only.plugin.ts:2 import { APIError } from "better-auth"; ^^^^^^^^ SyntaxError: The requested module 'better-auth' does not provide an export named 'APIError' at ModuleJob._instantiate (node:internal/modules/esm/module_job:177:21) at async ModuleJob.run (node:internal/modules/esm/module_job:260:5) at async onImport.tracePromise.__proto__ (node:internal/modules/esm/loader:543:26) at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:116:5) ``` can be fixed with `import { APIError } from "better-auth/api";` ### Current vs. Expected behavior the type probably shouldnt be exported (or the runtime should be?) --- I'm guessing this could be an issue for more than `APIError`, as I noticed this line `export * from 'better-call';` in `better-auth/dist/index.d.ts` same issue with `import { z } from "better-auth";` (TS is fine with this) due to `export * from 'zod';` also in `better-auth/dist/index.d.ts` ### What version of Better Auth are you using? 1.1.17 ### Provide environment information ```bash Node.js v22.11.0 ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the bug label 2026-03-13 08:00:51 -05:00
Author
Owner

@Bekacru commented on GitHub (Mar 24, 2025):

import it from better-auth/error or use throw ctx.error()

@Bekacru commented on GitHub (Mar 24, 2025): import it from `better-auth/error` or use `throw ctx.error()`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#701