[GH-ISSUE #3945] Adding telemetry to Better Auth broke support for non-node.js environments #9770

Closed
opened 2026-04-13 05:28:17 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @lucasoliveirabr on GitHub (Aug 12, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3945

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a backend project with Cloudflare Workers and Hono and try to run it without Workers support for Node.js.

Error logs:
X [ERROR] Build failed with 5 errors:

X [ERROR] Could not resolve "fs/promises"

  node_modules/better-auth/dist/index.mjs:39:7:
    39 │ import 'fs/promises';
       ╵        ~~~~~~~~~~~~~

The package "fs/promises" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.

X [ERROR] Could not resolve "path"

  node_modules/better-auth/dist/index.mjs:40:7:
    40 │ import 'path';
       ╵        ~~~~~~

The package "path" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.

X [ERROR] Could not resolve "fs/promises"

  node_modules/better-auth/dist/shared/better-auth.CCMYns0n.mjs:27:15:
    27 │ import fs from 'fs/promises';
       ╵                ~~~~~~~~~~~~~

The package "fs/promises" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.

X [ERROR] Could not resolve "path"

  node_modules/better-auth/dist/shared/better-auth.CCMYns0n.mjs:28:17:
    28 │ import path from 'path';
       ╵                  ~~~~~~

The package "path" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.

X [ERROR] Could not resolve "fs"

  node_modules/better-auth/dist/shared/better-auth.CCMYns0n.mjs:182:39:
    182 │   const { default: fs } = await import('fs');
        ╵                                        ~~~~

The package "fs" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.

Current vs. Expected behavior

Until v1.3.4, Better Auth worked normally with non-node.js environments. Now with v1.3.5, with the addition of built-in node.js modules to make telemetry work, it's not possible to run it unless adding node.js support to the environment, which isn't possible or desirable in some cases.

What version of Better Auth are you using?

v1.3.5

System info

Framework: Hono
Environment: Cloudflare Workers

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

Backend

Auth config (if applicable)


Additional context

No response

Originally created by @lucasoliveirabr on GitHub (Aug 12, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3945 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Create a backend project with Cloudflare Workers and Hono and try to run it without Workers support for Node.js. **Error logs:** X [ERROR] Build failed with 5 errors: X [ERROR] Could not resolve "fs/promises" node_modules/better-auth/dist/index.mjs:39:7: 39 │ import 'fs/promises'; ╵ ~~~~~~~~~~~~~ The package "fs/promises" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project. X [ERROR] Could not resolve "path" node_modules/better-auth/dist/index.mjs:40:7: 40 │ import 'path'; ╵ ~~~~~~ The package "path" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project. X [ERROR] Could not resolve "fs/promises" node_modules/better-auth/dist/shared/better-auth.CCMYns0n.mjs:27:15: 27 │ import fs from 'fs/promises'; ╵ ~~~~~~~~~~~~~ The package "fs/promises" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project. X [ERROR] Could not resolve "path" node_modules/better-auth/dist/shared/better-auth.CCMYns0n.mjs:28:17: 28 │ import path from 'path'; ╵ ~~~~~~ The package "path" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project. X [ERROR] Could not resolve "fs" node_modules/better-auth/dist/shared/better-auth.CCMYns0n.mjs:182:39: 182 │ const { default: fs } = await import('fs'); ╵ ~~~~ The package "fs" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project. ### Current vs. Expected behavior Until v1.3.4, Better Auth worked normally with non-node.js environments. Now with v1.3.5, with the addition of built-in node.js modules to make telemetry work, it's not possible to run it unless adding node.js support to the environment, which isn't possible or desirable in some cases. ### What version of Better Auth are you using? v1.3.5 ### System info ```bash Framework: Hono Environment: Cloudflare Workers ``` ### Which area(s) are affected? (Select all that apply) Backend ### Auth config (if applicable) ```typescript ``` ### Additional context _No response_
GiteaMirror added the locked label 2026-04-13 05:28:17 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 12, 2025):

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

Telemetry added in Better Auth v1.3.5 introduced imports of Node.js modules like fs/promises and path, which break compatibility with non-Node.js environments such as Cloudflare Workers. These imports are present in the distributed package and cause build failures unless you enable the nodejs_compat flag, which isn't always possible or desirable for serverless platforms like Workers. Disabling telemetry via config (telemetry: { enabled: false }) or the BETTER_AUTH_TELEMETRY=0 environment variable may help, but if the imports are unconditional, it won't fully resolve the build errors—static imports will still be processed by your bundler or runtime regardless of config settings [source].

There are ongoing discussions and workarounds, including forks that conditionally import Node.js modules only when needed, but the maintainers have acknowledged the problem and are planning improvements [source]. For now, if you can't use the compatibility flag, you may need to stick with v1.3.4 or patch the package to avoid unconditional imports. Keep an eye on future releases for a more robust fix.

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:3178553773 --> @dosubot[bot] commented on GitHub (Aug 12, 2025): <!-- Greeting --> Hi @lucasoliveirabr! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> Telemetry added in Better Auth v1.3.5 introduced imports of Node.js modules like `fs/promises` and `path`, which break compatibility with non-Node.js environments such as Cloudflare Workers. These imports are present in the distributed package and cause build failures unless you enable the `nodejs_compat` flag, which isn't always possible or desirable for serverless platforms like Workers. Disabling telemetry via config (`telemetry: { enabled: false }`) or the `BETTER_AUTH_TELEMETRY=0` environment variable may help, but if the imports are unconditional, it won't fully resolve the build errors—static imports will still be processed by your bundler or runtime regardless of config settings [[source](https://github.com/better-auth/better-auth/pull/3942)]. There are ongoing discussions and workarounds, including forks that conditionally import Node.js modules only when needed, but the maintainers have acknowledged the problem and are planning improvements [[source](https://github.com/better-auth/better-auth/issues/593)]. For now, if you can't use the compatibility flag, you may need to stick with v1.3.4 or patch the package to avoid unconditional imports. Keep an eye on future releases for a more robust fix. <!-- 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/114030ff-d97e-4182-91aa-9ab65068f751?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/114030ff-d97e-4182-91aa-9ab65068f751?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/114030ff-d97e-4182-91aa-9ab65068f751?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/114030ff-d97e-4182-91aa-9ab65068f751?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/114030ff-d97e-4182-91aa-9ab65068f751?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/114030ff-d97e-4182-91aa-9ab65068f751?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/114030ff-d97e-4182-91aa-9ab65068f751?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/3945)
Author
Owner

@Bekacru commented on GitHub (Aug 12, 2025):

Hey, could you check if 1.3.6-beta.1 addressed the issue

<!-- gh-comment-id:3180147064 --> @Bekacru commented on GitHub (Aug 12, 2025): Hey, could you check if 1.3.6-beta.1 addressed the issue
Author
Owner

@lucasoliveirabr commented on GitHub (Aug 13, 2025):

@Bekacru Still broken in v1.3.6 (not beta), with the same, but fewer, errors:

X [ERROR] Build failed with 2 errors:

X [ERROR] Could not resolve "path"

  node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs:539:28:
    539 │   const path = await import('path');
        ╵                             ~~~~~~

The package "path" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.

X [ERROR] Could not resolve "os"

  node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs:540:26:
    540 │   const os = await import('os');
        ╵                           ~~~~

The package "os" wasn't found on the file system but is built into node.
- Add the "nodejs_compat" compatibility flag to your project.
<!-- gh-comment-id:3182831237 --> @lucasoliveirabr commented on GitHub (Aug 13, 2025): @Bekacru Still broken in v1.3.6 (not beta), with the same, but fewer, errors: X [ERROR] Build failed with 2 errors: X [ERROR] Could not resolve "path" node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs:539:28: 539 │ const path = await import('path'); ╵ ~~~~~~ The package "path" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project. X [ERROR] Could not resolve "os" node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs:540:26: 540 │ const os = await import('os'); ╵ ~~~~ The package "os" wasn't found on the file system but is built into node. - Add the "nodejs_compat" compatibility flag to your project.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#9770