[GH-ISSUE #4430] Export generator function from OpenAPI plugin for direct usage #18561

Closed
opened 2026-04-15 17:03:42 -05:00 by GiteaMirror · 4 comments
Owner

Originally created by @hyunrealshadow on GitHub (Sep 4, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4430

Originally assigned to: @himself65 on GitHub.

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

I'm trying to directly use this function:
158841dd91/packages/better-auth/src/plugins/open-api/generator.ts (L283-L485)

In node_modules/dist/better-auth/plugins/index.mjs:

export { openAPI } from './open-api/index.mjs';

But in node_modules/dist/better-auth/plugins/index.d.ts:

export { OpenAPIOptions, Path, generator, openAPI } from './open-api/index.js';

Current vs. Expected behavior

index.mjs only exports openAPI.

index.d.ts declares additional exports (OpenAPIOptions, Path, generator, openAPI).

This causes a mismatch: TypeScript allows importing generator, but at runtime it is not available from index.mjs.

What version of Better Auth are you using?

^1.3.8

System info

System:
    OS: Windows 11 10.0.26100
    CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor            
    Memory: 34.89 GB / 63.93 GB
  Browsers:
    Edge: Chromium (139.0.3405.125)
    Internet Explorer: 11.0.26100.1882

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

Package, Types, Other

Auth config (if applicable)


Additional context

No response

Originally created by @hyunrealshadow on GitHub (Sep 4, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4430 Originally assigned to: @himself65 on GitHub. ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce I'm trying to directly use this function: https://github.com/better-auth/better-auth/blob/158841dd91681fa7803b0eda2d6240c2e5643f48/packages/better-auth/src/plugins/open-api/generator.ts#L283-L485 In node_modules/dist/better-auth/plugins/index.mjs: ```js export { openAPI } from './open-api/index.mjs'; ``` But in node_modules/dist/better-auth/plugins/index.d.ts: ```ts export { OpenAPIOptions, Path, generator, openAPI } from './open-api/index.js'; ``` ### Current vs. Expected behavior index.mjs only exports openAPI. index.d.ts declares additional exports (OpenAPIOptions, Path, generator, openAPI). This causes a mismatch: TypeScript allows importing generator, but at runtime it is not available from index.mjs. ### What version of Better Auth are you using? ^1.3.8 ### System info ```bash System: OS: Windows 11 10.0.26100 CPU: (32) x64 AMD Ryzen 9 5950X 16-Core Processor Memory: 34.89 GB / 63.93 GB Browsers: Edge: Chromium (139.0.3405.125) Internet Explorer: 11.0.26100.1882 ``` ### Which area(s) are affected? (Select all that apply) Package, Types, Other ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-15 17:03:42 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Sep 4, 2025):

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

The mismatch happens because the TypeScript declaration file (index.d.ts) lists exports like generator, OpenAPIOptions, and Path from the open-api plugin, but the runtime JavaScript module (index.mjs) only exports openAPI. This means TypeScript will let you import generator from better-auth/plugins, but at runtime, it's not actually available, leading to errors.

This is a known issue in Better Auth plugins—recent fixes for other plugins (like siwe) involved updating both the build config and index files so runtime exports match the type declarations. The root cause is likely an oversight in the export statements of index.mjs and can be resolved by updating it to export all the symbols listed in index.d.ts see example PR.

For now, you can work around this by importing generator directly from its source path:

import { generator } from 'better-auth/plugins/open-api/generator.js';

This will give you access to the function at runtime.

If you need the exports to match for all consumers, updating index.mjs to also export generator, OpenAPIOptions, and Path (just like in index.d.ts) is the recommended fix. This pattern has been used to resolve similar issues in other plugins see details.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

<!-- gh-comment-id:3254093393 --> @dosubot[bot] commented on GitHub (Sep 4, 2025): <!-- Greeting --> Hi @hyunrealshadow! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The mismatch happens because the TypeScript declaration file (`index.d.ts`) lists exports like `generator`, `OpenAPIOptions`, and `Path` from the open-api plugin, but the runtime JavaScript module (`index.mjs`) only exports `openAPI`. This means TypeScript will let you import `generator` from `better-auth/plugins`, but at runtime, it's not actually available, leading to errors. This is a known issue in Better Auth plugins—recent fixes for other plugins (like `siwe`) involved updating both the build config and index files so runtime exports match the type declarations. The root cause is likely an oversight in the export statements of `index.mjs` and can be resolved by updating it to export all the symbols listed in `index.d.ts` [see example PR](https://github.com/better-auth/better-auth/pull/3503). For now, you can work around this by importing `generator` directly from its source path: ```js import { generator } from 'better-auth/plugins/open-api/generator.js'; ``` This will give you access to the function at runtime. If you need the exports to match for all consumers, updating `index.mjs` to also export `generator`, `OpenAPIOptions`, and `Path` (just like in `index.d.ts`) is the recommended fix. This pattern has been used to resolve similar issues in other plugins [see details](https://github.com/better-auth/better-auth/pull/3596). <!-- 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/683729d9-6193-4f81-a82d-65c801337df5?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/683729d9-6193-4f81-a82d-65c801337df5?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/683729d9-6193-4f81-a82d-65c801337df5?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/683729d9-6193-4f81-a82d-65c801337df5?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/683729d9-6193-4f81-a82d-65c801337df5?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/683729d9-6193-4f81-a82d-65c801337df5?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/683729d9-6193-4f81-a82d-65c801337df5?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/4430)
Author
Owner

@himself65 commented on GitHub (Sep 4, 2025):

maybe a bundler issue? Let me check what's happening

<!-- gh-comment-id:3256375602 --> @himself65 commented on GitHub (Sep 4, 2025): maybe a bundler issue? Let me check what's happening
Author
Owner

@himself65 commented on GitHub (Sep 4, 2025):

no, we only export the type, not the runtime function. But I think it's okay to export the generator function if you want

<!-- gh-comment-id:3256413799 --> @himself65 commented on GitHub (Sep 4, 2025): no, we only export the type, not the runtime function. But I think it's okay to export the generator function if you want
Author
Owner

@hyunrealshadow commented on GitHub (Sep 5, 2025):

@himself65
I realized I overlooked the export type. Sorry about that. So, is it possible to directly export this function?

<!-- gh-comment-id:3256766221 --> @hyunrealshadow commented on GitHub (Sep 5, 2025): @himself65 I realized I overlooked the export type. Sorry about that. So, is it possible to directly export this function?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#18561