[GH-ISSUE #6024] Failed to fetch dynamically imported module: node:async_hooks #27727

Closed
opened 2026-04-17 18:54:09 -05:00 by GiteaMirror · 5 comments
Owner

Originally created by @ijmozn on GitHub (Nov 16, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6024

I am using NextJS 16 (turbopack) with better auth version 1.4.0-beta.20
and getting this error Failed to fetch dynamically imported module: node:async_hooks
seems like fixed PR-5555 previously but I do still have this issue of importing Node.js built-in modules.

Originally created by @ijmozn on GitHub (Nov 16, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6024 I am using NextJS 16 (turbopack) with better auth version `1.4.0-beta.20` and getting this error `Failed to fetch dynamically imported module: node:async_hooks` seems like fixed [PR-5555](https://github.com/better-auth/better-auth/pull/5555) previously but I do still have this issue of importing Node.js built-in modules.
GiteaMirror added the lockedbug labels 2026-04-17 18:54:10 -05:00
Author
Owner

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

It looks like you’re still hitting the dynamic import issue with the Node.js built-in module "node:async_hooks" when using NextJS 16 with turbopack and Better Auth 1.4.0-beta.20—even though the referenced fix in PR-5555 should have addressed it. Here are a few troubleshooting steps:

• First, verify that you’re running a compatible Node.js version (v16 or later) since Better Auth requires appropriate Node.js support for ESM and built-in modules [1].
• Double-check your turbopack and NextJS configuration to ensure that native Node.js modules are correctly handled—turbopack sometimes needs extra configuration for Node built-ins.
• Consider cleaning your build cache and reinstalling dependencies to ensure the latest patch from PR-5555 is correctly applied.
• If the problem persists, you might try testing the same setup in a more standard environment (e.g. switching to webpack temporarily) to isolate whether it’s an issue specific to turbopack’s handling.

Tag @better-auth-agent if you would like an answer from the Agent.

Could you let me know if any of these steps help or if you have additional configuration details to share?

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3539066086 --> @better-auth-agent[bot] commented on GitHub (Nov 16, 2025): It looks like you’re still hitting the dynamic import issue with the Node.js built-in module "node:async_hooks" when using NextJS 16 with turbopack and Better Auth 1.4.0-beta.20—even though the referenced fix in PR-5555 should have addressed it. Here are a few troubleshooting steps: • First, verify that you’re running a compatible Node.js version (v16 or later) since Better Auth requires appropriate Node.js support for ESM and built-in modules [[1]](https://www.better-auth.com/docs/reference/contributing). • Double-check your turbopack and NextJS configuration to ensure that native Node.js modules are correctly handled—turbopack sometimes needs extra configuration for Node built-ins. • Consider cleaning your build cache and reinstalling dependencies to ensure the latest patch from PR-5555 is correctly applied. • If the problem persists, you might try testing the same setup in a more standard environment (e.g. switching to webpack temporarily) to isolate whether it’s an issue specific to turbopack’s handling. Tag @better-auth-agent if you would like an answer from the Agent. Could you let me know if any of these steps help or if you have additional configuration details to share? <!-- 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)
Author
Owner

@dosubot[bot] commented on GitHub (Nov 16, 2025):

This error happens because better-auth imports Node.js built-in modules like node:async_hooks using dynamic imports, which aren't supported in environments like NextJS 16 with Turbopack or edge runtimes. Even though PR #5555 changed the import to use a direct string instead of a variable and is included in your version, it doesn't fully solve the problem for environments that can't resolve Node.js built-ins at runtime—so the error persists in setups like yours source.

This is a known limitation with better-auth in NextJS 16 (Turbopack). Workarounds include: using getSessionCookie instead of auth.api.getSession in middleware/proxy for better compatibility, downgrading to a version before Node.js built-ins were introduced (like 1.3.4), or patching the code to avoid unconditional imports source. There’s currently no official fix for full compatibility with Turbopack and NextJS 16, and some features may not work as expected until better-auth introduces stricter environment guards or a dedicated edge-compatible build.

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:3539070015 --> @dosubot[bot] commented on GitHub (Nov 16, 2025): <!-- Answer --> This error happens because better-auth imports Node.js built-in modules like `node:async_hooks` using dynamic imports, which aren't supported in environments like NextJS 16 with Turbopack or edge runtimes. Even though PR #5555 changed the import to use a direct string instead of a variable and is included in your version, it doesn't fully solve the problem for environments that can't resolve Node.js built-ins at runtime—so the error persists in setups like yours [source](https://github.com/better-auth/better-auth/pull/5555). This is a known limitation with better-auth in NextJS 16 (Turbopack). Workarounds include: using `getSessionCookie` instead of `auth.api.getSession` in middleware/proxy for better compatibility, downgrading to a version before Node.js built-ins were introduced (like 1.3.4), or patching the code to avoid unconditional imports [source](https://github.com/better-auth/better-auth/issues/5539). There’s currently no official fix for full compatibility with Turbopack and NextJS 16, and some features may not work as expected until better-auth introduces stricter environment guards or a dedicated edge-compatible build. <!-- 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/466b223c-98ac-4a7c-8308-d0629170503f?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/466b223c-98ac-4a7c-8308-d0629170503f?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/466b223c-98ac-4a7c-8308-d0629170503f?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/466b223c-98ac-4a7c-8308-d0629170503f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/466b223c-98ac-4a7c-8308-d0629170503f?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/466b223c-98ac-4a7c-8308-d0629170503f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/466b223c-98ac-4a7c-8308-d0629170503f?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/6024)
Author
Owner

@qweered commented on GitHub (Nov 24, 2025):

Duplicate of #5539

<!-- gh-comment-id:3572968325 --> @qweered commented on GitHub (Nov 24, 2025): Duplicate of #5539
Author
Owner

@ping-maxwell commented on GitHub (Jan 8, 2026):

Hello all, this should be resolved by now, please try latest version of better-auth.

If this is still an issue please tag me, I'm happy to re-open it.

<!-- gh-comment-id:3724040188 --> @ping-maxwell commented on GitHub (Jan 8, 2026): Hello all, this should be resolved by now, please try latest version of better-auth. If this is still an issue please tag me, I'm happy to re-open it.
Author
Owner

@pieter-berkel commented on GitHub (Jan 8, 2026):

@ping-maxwell , I updated to version 1.4.10 and still get the following error:

ERROR [Better Auth]: Error [Error: Uncaught TypeError: dynamic module import unsupported at <anonymous> (../../../node_modules/.bun/@better-auth+core@1.4.5+abbb897419d9c18e/node_modules/@better-auth/core/dist/async_hooks-BfRfbd1J.mjs:1:33) ]

<!-- gh-comment-id:3724836521 --> @pieter-berkel commented on GitHub (Jan 8, 2026): @ping-maxwell , I updated to version 1.4.10 and still get the following error: `ERROR [Better Auth]: Error [Error: Uncaught TypeError: dynamic module import unsupported at <anonymous> (../../../node_modules/.bun/@better-auth+core@1.4.5+abbb897419d9c18e/node_modules/@better-auth/core/dist/async_hooks-BfRfbd1J.mjs:1:33) ]`
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27727