[GH-ISSUE #3973] Environments without built-in node modules fail because of os and path imports #27103

Closed
opened 2026-04-17 17:55:09 -05:00 by GiteaMirror Ā· 4 comments
Owner

Originally created by @alfredomariamilano on GitHub (Aug 13, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/3973

Hi! šŸ‘‹

Firstly, thanks for your work on this project! šŸ™‚

Today I used patch-package to patch better-auth@1.3.6 for the project I'm working on.

Environments without built-in node modules fail because of dynamic imports of os and path required for telemetry. For me, it happens in Convex, even when I disable telemetry. It is not a good fix, but it works for me for now.

Here is the diff that solved my problem:

diff --git a/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs b/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs
index 15b6790..08707e5 100644
--- a/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs
+++ b/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs
@@ -536,12 +536,17 @@ Learn more in the docs: https://www.better-auth.com/docs/reference/telemetry
 
 `;
 async function configFilePath() {
-  const path = await import('path');
-  const os = await import('os');
-  const baseDir = typeof process !== "undefined" && process.platform === "win32" ? process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming") : path.join(os.homedir(), ".config");
-  const dir = path.join(baseDir, "better-auth");
-  const file = path.join(dir, "telemetry.json");
-  return { file, dir };
+  try {
+    const path = await import('path');
+    const os = await import('os');
+    const baseDir = typeof process !== "undefined" && process.platform === "win32" ? process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming") : path.join(os.homedir(), ".config");
+    const dir = path.join(baseDir, "better-auth");
+    const file = path.join(dir, "telemetry.json");
+    return { file, dir };
+  } catch (error) {
+    console.error(error)
+    return { file: '', dir: '' };
+  }
 }
 const shownNoticeInProcess = /* @__PURE__ */ new Set();
 async function hasShownNoticeBefore(anonymousId) {

This issue body was partially generated by patch-package.

Originally created by @alfredomariamilano on GitHub (Aug 13, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/3973 Hi! šŸ‘‹ Firstly, thanks for your work on this project! šŸ™‚ Today I used [patch-package](https://github.com/ds300/patch-package) to patch `better-auth@1.3.6` for the project I'm working on. Environments without built-in node modules fail because of dynamic imports of os and path required for telemetry. For me, it happens in Convex, even when I disable telemetry. It is not a good fix, but it works for me for now. Here is the diff that solved my problem: ```diff diff --git a/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs b/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs index 15b6790..08707e5 100644 --- a/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs +++ b/node_modules/better-auth/dist/shared/better-auth.BY1-gjw3.mjs @@ -536,12 +536,17 @@ Learn more in the docs: https://www.better-auth.com/docs/reference/telemetry `; async function configFilePath() { - const path = await import('path'); - const os = await import('os'); - const baseDir = typeof process !== "undefined" && process.platform === "win32" ? process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming") : path.join(os.homedir(), ".config"); - const dir = path.join(baseDir, "better-auth"); - const file = path.join(dir, "telemetry.json"); - return { file, dir }; + try { + const path = await import('path'); + const os = await import('os'); + const baseDir = typeof process !== "undefined" && process.platform === "win32" ? process.env.APPDATA || path.join(os.homedir(), "AppData", "Roaming") : path.join(os.homedir(), ".config"); + const dir = path.join(baseDir, "better-auth"); + const file = path.join(dir, "telemetry.json"); + return { file, dir }; + } catch (error) { + console.error(error) + return { file: '', dir: '' }; + } } const shownNoticeInProcess = /* @__PURE__ */ new Set(); async function hasShownNoticeBefore(anonymousId) { ``` <em>This issue body was [partially generated by patch-package](https://github.com/ds300/patch-package/issues/296).</em>
GiteaMirror added the lockedbug labels 2026-04-17 17:55:09 -05:00
Author
Owner

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

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

This is a known issue: telemetry in better-auth introduced imports of Node.js modules like os and path, which break compatibility with environments that don't provide Node built-ins (like Convex, Cloudflare Workers, or edge runtimes). Disabling telemetry via config or environment variable doesn't fully prevent these errors, because the imports are still processed by bundlers or runtimes—even if telemetry is offĀ see discussion.

Your patch (wrapping imports in a try-catch) is a reasonable workaround for 1.3.6, but an official fix has now landed: as of PRĀ #3947 (merged 2025-08-13), better-auth replaces static imports with dynamic imports and adds runtime checks to avoid loading Node modules in unsupported environments. This should resolve failures in Convex and similar platforms.

To robustly support non-Node environments, upgrade to the latest version of better-auth (after PRĀ #3947). If you can't upgrade, patching or pinning to a pre-telemetry version (≤1.3.4) is a temporary workaround.

Telemetry can be disabled in your config (telemetry: { enabled: false }) or with the BETTER_AUTH_TELEMETRY=0 env variable. You can also audit telemetry data by setting BETTER_AUTH_TELEMETRY_DEBUG=1 or telemetry: { debug: true }Ā see docs.

Let me know if you need details on the upgrade or config!

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:3184032894 --> @dosubot[bot] commented on GitHub (Aug 13, 2025): <!-- Greeting --> Hi @alfredomariamilano! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This is a known issue: telemetry in better-auth introduced imports of Node.js modules like `os` and `path`, which break compatibility with environments that don't provide Node built-ins (like Convex, Cloudflare Workers, or edge runtimes). Disabling telemetry via config or environment variable doesn't fully prevent these errors, because the imports are still processed by bundlers or runtimes—even if telemetry is offĀ [see discussion](https://github.com/better-auth/better-auth/issues/3945#issuecomment-3178553773). Your patch (wrapping imports in a try-catch) is a reasonable workaround for 1.3.6, but an official fix has now landed: as of PRĀ [#3947](https://github.com/better-auth/better-auth/pull/3947) (merged 2025-08-13), better-auth replaces static imports with dynamic imports and adds runtime checks to avoid loading Node modules in unsupported environments. This should resolve failures in Convex and similar platforms. To robustly support non-Node environments, upgrade to the latest version of better-auth (after PRĀ #3947). If you can't upgrade, patching or pinning to a pre-telemetry version (≤1.3.4) is a temporary workaround. Telemetry can be disabled in your config (`telemetry: { enabled: false }`) or with the `BETTER_AUTH_TELEMETRY=0` env variable. You can also audit telemetry data by setting `BETTER_AUTH_TELEMETRY_DEBUG=1` or `telemetry: { debug: true }`Ā [see docs](https://github.com/better-auth/better-auth/pull/3942). Let me know if you need details on the upgrade or config! <!-- 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/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=hallucination) | [Report šŸ›](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?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/3973)
Author
Owner

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

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

This is a known issue: telemetry in better-auth introduced imports of Node.js modules like os and path, which break compatibility with environments that don't provide Node built-ins (like Convex, Cloudflare Workers, or edge runtimes). Disabling telemetry via config or environment variable doesn't fully prevent these errors, because the imports are still processed by bundlers or runtimes—even if telemetry is offĀ see discussion.

Your patch (wrapping imports in a try-catch) is a reasonable workaround for 1.3.6, but an official fix has now landed: as of PRĀ #3947 (merged 2025-08-13), better-auth replaces static imports with dynamic imports and adds runtime checks to avoid loading Node modules in unsupported environments. This should resolve failures in Convex and similar platforms.

To robustly support non-Node environments, upgrade to the latest version of better-auth (after PRĀ #3947). If you can't upgrade, patching or pinning to a pre-telemetry version (≤1.3.4) is a temporary workaround.

Telemetry can be disabled in your config (telemetry: { enabled: false }) or with the BETTER_AUTH_TELEMETRY=0 env variable. You can also audit telemetry data by setting BETTER_AUTH_TELEMETRY_DEBUG=1 or telemetry: { debug: true }Ā see docs.

Let me know if you need details on the upgrade or config!

To reply, just mention @dosu.

How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report šŸ› | OtherĀ Ā Chat with DosuĀ Join DiscordĀ Share on X

Absolutely, by I was still getting the error in Convex, even with telemetry.enabled set to false on better-auth@1.3.6

<!-- gh-comment-id:3184086656 --> @alfredomariamilano commented on GitHub (Aug 13, 2025): > Hi [@alfredomariamilano](https://github.com/alfredomariamilano)! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. > > This is a known issue: telemetry in better-auth introduced imports of Node.js modules like `os` and `path`, which break compatibility with environments that don't provide Node built-ins (like Convex, Cloudflare Workers, or edge runtimes). Disabling telemetry via config or environment variable doesn't fully prevent these errors, because the imports are still processed by bundlers or runtimes—even if telemetry is offĀ [see discussion](https://github.com/better-auth/better-auth/issues/3945#issuecomment-3178553773). > > Your patch (wrapping imports in a try-catch) is a reasonable workaround for 1.3.6, but an official fix has now landed: as of PRĀ [#3947](https://github.com/better-auth/better-auth/pull/3947) (merged 2025-08-13), better-auth replaces static imports with dynamic imports and adds runtime checks to avoid loading Node modules in unsupported environments. This should resolve failures in Convex and similar platforms. > > To robustly support non-Node environments, upgrade to the latest version of better-auth (after PRĀ [#3947](https://github.com/better-auth/better-auth/pull/3947)). If you can't upgrade, patching or pinning to a pre-telemetry version (≤1.3.4) is a temporary workaround. > > Telemetry can be disabled in your config (`telemetry: { enabled: false }`) or with the `BETTER_AUTH_TELEMETRY=0` env variable. You can also audit telemetry data by setting `BETTER_AUTH_TELEMETRY_DEBUG=1` or `telemetry: { debug: true }`Ā [see docs](https://github.com/better-auth/better-auth/pull/3942). > > Let me know if you need details on the upgrade or config! > > _To reply, just mention [@dosu](https://go.dosu.dev/dosubot)._ > > How did I do? [Good](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=hallucination) | [Report šŸ›](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/348afcd7-d059-4f09-a84b-9421b60cb305?feedback_type=other)Ā Ā [![Chat with Dosu](https://camo.githubusercontent.com/d9ffebb979729c9ef0fc4e3090dbae5b17cabbfec8afe378ada6b81913d6ad8a/68747470733a2f2f646f73752e6465762f646f73752d636861742d62616467652e737667)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)Ā [![Join Discord](https://camo.githubusercontent.com/d562c2df5e4567ea41d37f1d91a4da0839d8341037045b103b2da268998de17f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6a6f696e2d3538363546323f6c6f676f3d646973636f7264266c6f676f436f6c6f723d7768697465266c6162656c3d)](https://go.dosu.dev/discord-bot)Ā [![Share on X](https://camo.githubusercontent.com/4649f705e2396d6f328dbc8e800a0509c9c17b3b20253b36706c393df124b93d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f582d73686172652d626c61636b)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/3973) Absolutely, by I was still getting the error in Convex, even with telemetry.enabled set to false on better-auth@1.3.6
Author
Owner

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

You’re still seeing import errors in Convex with better-auth@1.3.6—even with telemetry disabled—because the telemetry code always tries to dynamically import Node.js modules like os and path without any runtime guards. Disabling telemetry via config or environment variable doesn’t prevent these imports from being processed by the bundler or runtime, so errors persist in environments without Node built-insĀ see details.

Your patch (wrapping the imports in a try-catch) is a solid workaround for 1.3.6, but the official fix is now merged: PRĀ #3947 adds runtime checks and lazy imports, so Node modules are only loaded when safe. Upgrading to the latest version after this PR is the recommended solution for robust support in Convex and similar platforms.

If you can’t upgrade right now, patching the telemetry code (as you did) or pinning to a pre-telemetry version (≤1.3.4) are the only reliable workarounds. There aren’t any other documented fixes for this specific scenario.

Let me know if you want upgrade instructions or details on the config!

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:3184101341 --> @dosubot[bot] commented on GitHub (Aug 13, 2025): <!-- Answer --> You’re still seeing import errors in Convex with better-auth@1.3.6—even with telemetry disabled—because the telemetry code always tries to dynamically import Node.js modules like `os` and `path` without any runtime guards. Disabling telemetry via config or environment variable doesn’t prevent these imports from being processed by the bundler or runtime, so errors persist in environments without Node built-insĀ [see details](https://github.com/better-auth/better-auth/issues/3945). Your patch (wrapping the imports in a try-catch) is a solid workaround for 1.3.6, but the official fix is now merged: PRĀ [#3947](https://github.com/better-auth/better-auth/pull/3947) adds runtime checks and lazy imports, so Node modules are only loaded when safe. Upgrading to the latest version after this PR is the recommended solution for robust support in Convex and similar platforms. If you can’t upgrade right now, patching the telemetry code (as you did) or pinning to a pre-telemetry version (≤1.3.4) are the only reliable workarounds. There aren’t any other documented fixes for this specific scenario. Let me know if you want upgrade instructions or details on the config! <!-- 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/93ec58c0-600f-438c-8683-f9bac6e2beaf?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/93ec58c0-600f-438c-8683-f9bac6e2beaf?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/93ec58c0-600f-438c-8683-f9bac6e2beaf?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/93ec58c0-600f-438c-8683-f9bac6e2beaf?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/93ec58c0-600f-438c-8683-f9bac6e2beaf?feedback_type=hallucination) | [Report šŸ›](https://app.dosu.dev/response-feedback/93ec58c0-600f-438c-8683-f9bac6e2beaf?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/93ec58c0-600f-438c-8683-f9bac6e2beaf?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/3973)
Author
Owner

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

it is already merged to canary. will be released patch release soon

<!-- gh-comment-id:3185318053 --> @Kinfe123 commented on GitHub (Aug 13, 2025): it is already merged to canary. will be released patch release soon
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27103