[GH-ISSUE #4471] React Native build issue on v1.3.8 #27269

Closed
opened 2026-04-17 18:11:33 -05:00 by GiteaMirror · 27 comments
Owner

Originally created by @goknsh on GitHub (Sep 5, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/4471

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Create a new expo app, install better-auth@1.3.8 and @better-auth/expo@1.3.8, setup according to docs, import a plugin from better-auth/client/plugins.

Reproduction: https://github.com/goknsh/better-auth-rn-build-issue-repro

Current vs. Expected behavior

Current error when running expo run:android:

Android Bundling failed 4641ms node_modules/expo-router/entry.js (1511 modules)
The package at "node_modules/jose/dist/node/esm/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".
It failed because the native React runtime does not include the Node standard library.
Learn more: https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries

What version of Better Auth are you using?

1.3.8

System info

N/A

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

Client

Auth config (if applicable)

N/A

Additional context

#1551 has come back.

Originally created by @goknsh on GitHub (Sep 5, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/4471 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce Create a new expo app, install `better-auth@1.3.8` and `@better-auth/expo@1.3.8`, setup [according to docs](https://www.better-auth.com/docs/integrations/expo), import a plugin from `better-auth/client/plugins`. Reproduction: https://github.com/goknsh/better-auth-rn-build-issue-repro ### Current vs. Expected behavior Current error when running `expo run:android`: ``` Android Bundling failed 4641ms node_modules/expo-router/entry.js (1511 modules) The package at "node_modules/jose/dist/node/esm/runtime/base64url.js" attempted to import the Node standard library module "node:buffer". It failed because the native React runtime does not include the Node standard library. Learn more: https://docs.expo.dev/workflow/using-libraries/#using-third-party-libraries ``` ### What version of Better Auth are you using? 1.3.8 ### System info ```bash N/A ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript N/A ``` ### Additional context #1551 has come back.
GiteaMirror added the locked label 2026-04-17 18:11:33 -05:00
Author
Owner

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

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

This error happens because the jose library imports Node.js built-ins like buffer, which aren't available in Expo/React Native environments. This is a known issue and has come up before when using Better Auth plugins that depend on jose or other Node-only modules in client code. Recent changes to the JWT plugin and related code paths still import jose unconditionally, so the problem can recur if any plugin or shared code path pulls in these dependencies—even from the client entrypoints [3498].

There isn't currently an official workaround documented for this specific scenario, but community workarounds for similar issues include:

  • Adding a jose override in your package.json to force a compatible version,
  • Installing react-native-webcrypto,
  • Importing 'react-native-webcrypto' at the top level of your app before activating any Better Auth plugins [4422].

However, these workarounds may not resolve all issues if the plugin or its dependencies still require other Node.js built-ins. The root cause is that some Better Auth plugins (especially those related to JWT or cryptography) are not fully environment-guarded and may import server-only code even from client entrypoints [4041].

If you only need authentication flows that don't rely on JWT or cryptographic plugins, you may be able to use other plugins from better-auth/client/plugins without hitting this error. But for JWT or anything that touches jose, you'll likely hit this bundling problem until the package introduces proper environment separation or React Native support.

For now, the safest approach is to avoid importing plugins that depend on jose or Node.js built-ins in your Expo/React Native app, or to isolate all auth logic that requires those plugins to a backend/server environment.

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:3259397653 --> @dosubot[bot] commented on GitHub (Sep 5, 2025): <!-- Greeting --> Hi @goknsh! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> This error happens because the `jose` library imports Node.js built-ins like `buffer`, which aren't available in Expo/React Native environments. This is a known issue and has come up before when using Better Auth plugins that depend on `jose` or other Node-only modules in client code. Recent changes to the JWT plugin and related code paths still import `jose` unconditionally, so the problem can recur if any plugin or shared code path pulls in these dependencies—even from the client entrypoints [[3498](https://github.com/better-auth/better-auth/issues/3498)]. There isn't currently an official workaround documented for this specific scenario, but community workarounds for similar issues include: - Adding a `jose` override in your `package.json` to force a compatible version, - Installing `react-native-webcrypto`, - Importing `'react-native-webcrypto'` at the top level of your app before activating any Better Auth plugins [[4422](https://github.com/better-auth/better-auth/issues/4422)]. However, these workarounds may not resolve all issues if the plugin or its dependencies still require other Node.js built-ins. The root cause is that some Better Auth plugins (especially those related to JWT or cryptography) are not fully environment-guarded and may import server-only code even from client entrypoints [[4041](https://github.com/better-auth/better-auth/pull/4041)]. If you only need authentication flows that don't rely on JWT or cryptographic plugins, you may be able to use other plugins from `better-auth/client/plugins` without hitting this error. But for JWT or anything that touches `jose`, you'll likely hit this bundling problem until the package introduces proper environment separation or React Native support. For now, the safest approach is to avoid importing plugins that depend on `jose` or Node.js built-ins in your Expo/React Native app, or to isolate all auth logic that requires those plugins to a backend/server environment. <!-- 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/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/2c837121-e4aa-4d7b-be6c-8ab7fdac9a37?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/4471)
Author
Owner

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

Related: https://github.com/better-auth/better-auth/issues/4422

<!-- gh-comment-id:3259402408 --> @himself65 commented on GitHub (Sep 5, 2025): Related: https://github.com/better-auth/better-auth/issues/4422
Author
Owner

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

Looks like #4433 partially fixes this, but as https://github.com/better-auth/better-auth/issues/4422#issuecomment-3253802324 mentions, we get an error subtle is undefined (which can be fixed by import 'react-native-webcrypto' before you import plugins).

<!-- gh-comment-id:3259432736 --> @goknsh commented on GitHub (Sep 5, 2025): Looks like #4433 partially fixes this, but as https://github.com/better-auth/better-auth/issues/4422#issuecomment-3253802324 mentions, we get an error `subtle is undefined` (which can be fixed by `import 'react-native-webcrypto'` before you import plugins).
Author
Owner

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

OK, thanks for letting me know. Let me try

<!-- gh-comment-id:3259657023 --> @himself65 commented on GitHub (Sep 5, 2025): OK, thanks for letting me know. Let me try
Author
Owner

@HoshangDEV commented on GitHub (Sep 11, 2025):

When I add the import 'react-native-webcrypto' it's fine while developing the app, but when I build it I get this error:

[RUN_GRADLEW]   - [📦] expo-splash-screen (0.30.10)
[RUN_GRADLEW]   - [📦] expo-system-ui (5.0.11)
[RUN_GRADLEW] - [📦] expo-web-browser (15.0.6)
[RUN_GRADLEW] > Configure project :react-native-reanimated
[RUN_GRADLEW] Android gradle plugin: 8.8.2
[RUN_GRADLEW] Gradle: 8.13
[RUN_GRADLEW] [Incubating] Problems report is available at: file:///tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/android/build/reports/problems/problems-report.html
[RUN_GRADLEW] FAILURE: Build failed with an exception.
[RUN_GRADLEW] * Where:
[RUN_GRADLEW] Build file '/tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/node_modules/react-native-webcrypto/android/build.gradle' line: 38
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] A problem occurred evaluating project ':react-native-webcrypto'.
[RUN_GRADLEW] > Could not find method compile() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
[RUN_GRADLEW] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
[RUN_GRADLEW] For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
[RUN_GRADLEW] 28 actionable tasks: 28 executed
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] > Get more help at https://help.gradle.org.
[RUN_GRADLEW] BUILD FAILED in 15s
[RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

Build failed
Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
npx -y eas-cli-local-build-plugin@1.0.171 eyJqb2IiOnsidHlwZSI6Im1hbmFn

I've created an example repo if anyone wants to check it out, and if you find a solution, it would be great. Thanks.

<!-- gh-comment-id:3279604267 --> @HoshangDEV commented on GitHub (Sep 11, 2025): When I add the `import 'react-native-webcrypto'` it's fine while developing the app, but when I build it I get this error: ``` [RUN_GRADLEW] - [📦] expo-splash-screen (0.30.10) [RUN_GRADLEW] - [📦] expo-system-ui (5.0.11) [RUN_GRADLEW] - [📦] expo-web-browser (15.0.6) [RUN_GRADLEW] > Configure project :react-native-reanimated [RUN_GRADLEW] Android gradle plugin: 8.8.2 [RUN_GRADLEW] Gradle: 8.13 [RUN_GRADLEW] [Incubating] Problems report is available at: file:///tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/android/build/reports/problems/problems-report.html [RUN_GRADLEW] FAILURE: Build failed with an exception. [RUN_GRADLEW] * Where: [RUN_GRADLEW] Build file '/tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/node_modules/react-native-webcrypto/android/build.gradle' line: 38 [RUN_GRADLEW] * What went wrong: [RUN_GRADLEW] A problem occurred evaluating project ':react-native-webcrypto'. [RUN_GRADLEW] > Could not find method compile() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. [RUN_GRADLEW] * Try: [RUN_GRADLEW] > Run with --stacktrace option to get the stack trace. [RUN_GRADLEW] > Run with --info or --debug option to get more log output. [RUN_GRADLEW] Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. [RUN_GRADLEW] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. [RUN_GRADLEW] For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. [RUN_GRADLEW] 28 actionable tasks: 28 executed [RUN_GRADLEW] > Run with --scan to get full insights. [RUN_GRADLEW] > Get more help at https://help.gradle.org. [RUN_GRADLEW] BUILD FAILED in 15s [RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information. Build failed Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information. npx -y eas-cli-local-build-plugin@1.0.171 eyJqb2IiOnsidHlwZSI6Im1hbmFn ``` I've **[created an example repo](https://github.com/HoshangDEV/expo-better-auth)** if anyone wants to check it out, and if you find a solution, it would be great. Thanks.
Author
Owner

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

I will take a look

<!-- gh-comment-id:3282763932 --> @himself65 commented on GitHub (Sep 11, 2025): I will take a look
Author
Owner

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

When I add the import 'react-native-webcrypto' it's fine while developing the app, but when I build it I get this error:

[RUN_GRADLEW]   - [📦] expo-splash-screen (0.30.10)
[RUN_GRADLEW]   - [📦] expo-system-ui (5.0.11)
[RUN_GRADLEW] - [📦] expo-web-browser (15.0.6)
[RUN_GRADLEW] > Configure project :react-native-reanimated
[RUN_GRADLEW] Android gradle plugin: 8.8.2
[RUN_GRADLEW] Gradle: 8.13
[RUN_GRADLEW] [Incubating] Problems report is available at: file:///tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/android/build/reports/problems/problems-report.html
[RUN_GRADLEW] FAILURE: Build failed with an exception.
[RUN_GRADLEW] * Where:
[RUN_GRADLEW] Build file '/tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/node_modules/react-native-webcrypto/android/build.gradle' line: 38
[RUN_GRADLEW] * What went wrong:
[RUN_GRADLEW] A problem occurred evaluating project ':react-native-webcrypto'.
[RUN_GRADLEW] > Could not find method compile() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
[RUN_GRADLEW] * Try:
[RUN_GRADLEW] > Run with --stacktrace option to get the stack trace.
[RUN_GRADLEW] > Run with --info or --debug option to get more log output.
[RUN_GRADLEW] Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
[RUN_GRADLEW] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
[RUN_GRADLEW] For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
[RUN_GRADLEW] 28 actionable tasks: 28 executed
[RUN_GRADLEW] > Run with --scan to get full insights.
[RUN_GRADLEW] > Get more help at https://help.gradle.org.
[RUN_GRADLEW] BUILD FAILED in 15s
[RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.

Build failed
Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information.
npx -y eas-cli-local-build-plugin@1.0.171 eyJqb2IiOnsidHlwZSI6Im1hbmFn

I've created an example repo if anyone wants to check it out, and if you find a solution, it would be great. Thanks.

I think you don't need to import react-native-webcrypto on the client side, please remove that in auth-client

<!-- gh-comment-id:3282858904 --> @himself65 commented on GitHub (Sep 11, 2025): > When I add the `import 'react-native-webcrypto'` it's fine while developing the app, but when I build it I get this error: > > ``` > [RUN_GRADLEW] - [📦] expo-splash-screen (0.30.10) > [RUN_GRADLEW] - [📦] expo-system-ui (5.0.11) > [RUN_GRADLEW] - [📦] expo-web-browser (15.0.6) > [RUN_GRADLEW] > Configure project :react-native-reanimated > [RUN_GRADLEW] Android gradle plugin: 8.8.2 > [RUN_GRADLEW] Gradle: 8.13 > [RUN_GRADLEW] [Incubating] Problems report is available at: file:///tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/android/build/reports/problems/problems-report.html > [RUN_GRADLEW] FAILURE: Build failed with an exception. > [RUN_GRADLEW] * Where: > [RUN_GRADLEW] Build file '/tmp/hoshang/eas-build-local-nodejs/8fa896c1-f1e4-4697-81e0-fa7bcd4270dc/build/node_modules/react-native-webcrypto/android/build.gradle' line: 38 > [RUN_GRADLEW] * What went wrong: > [RUN_GRADLEW] A problem occurred evaluating project ':react-native-webcrypto'. > [RUN_GRADLEW] > Could not find method compile() for arguments [com.facebook.react:react-native:+] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler. > [RUN_GRADLEW] * Try: > [RUN_GRADLEW] > Run with --stacktrace option to get the stack trace. > [RUN_GRADLEW] > Run with --info or --debug option to get more log output. > [RUN_GRADLEW] Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0. > [RUN_GRADLEW] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins. > [RUN_GRADLEW] For more on this, please refer to https://docs.gradle.org/8.13/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation. > [RUN_GRADLEW] 28 actionable tasks: 28 executed > [RUN_GRADLEW] > Run with --scan to get full insights. > [RUN_GRADLEW] > Get more help at https://help.gradle.org. > [RUN_GRADLEW] BUILD FAILED in 15s > [RUN_GRADLEW] Error: Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information. > > Build failed > Gradle build failed with unknown error. See logs for the "Run gradlew" phase for more information. > npx -y eas-cli-local-build-plugin@1.0.171 eyJqb2IiOnsidHlwZSI6Im1hbmFn > ``` > > I've **[created an example repo](https://github.com/HoshangDEV/expo-better-auth)** if anyone wants to check it out, and if you find a solution, it would be great. Thanks. I think you don't need to import react-native-webcrypto on the client side, please remove that in auth-client
Author
Owner

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

I just tried to build manually and it success, closing

<!-- gh-comment-id:3282860180 --> @himself65 commented on GitHub (Sep 11, 2025): I just tried to build manually and it success, closing
Author
Owner

@HoshangDEV commented on GitHub (Sep 12, 2025):

I don't get one thing, in the first place I have this error while developing the app subtle is undefined, and to fix that I have to import import 'react-native-webcrypto' in the auth-client.ts, and if I want to build the app I have to remove that import?

<!-- gh-comment-id:3283388298 --> @HoshangDEV commented on GitHub (Sep 12, 2025): I don't get one thing, in the first place I have this error while developing the app `subtle is undefined`, and to fix that I have to import `import 'react-native-webcrypto'` in the `auth-client.ts`, and if I want to build the app I have to remove that import?
Author
Owner

@HoshangDEV commented on GitHub (Sep 12, 2025):

@himself65 I built an APK with plugins (such as twoFactorClient) and without import 'react-native-webcrypto', it would be built, but when I open the APK it's going to be stuck in the splash screen forever, aka not working.

The only fast solution for this, I think, is creating a demo/example of how to use better-auth in React Native or Expo with plugins (Client Side only). It would be great.

<!-- gh-comment-id:3284258223 --> @HoshangDEV commented on GitHub (Sep 12, 2025): @himself65 I built an **APK** with **plugins** (such as twoFactorClient) and without `import 'react-native-webcrypto'`, it would be built, but when I open the APK it's going to be **stuck in the splash screen** forever, aka not working. The only fast **solution** for this, I think, is creating a demo/example of how to use better-auth in React Native or Expo with plugins **(Client Side only)**. It would be great.
Author
Owner

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

Can you reproduce that in https://github.com/better-auth/examples/tree/main/expo-example? That will be great

<!-- gh-comment-id:3284282302 --> @himself65 commented on GitHub (Sep 12, 2025): Can you reproduce that in https://github.com/better-auth/examples/tree/main/expo-example? That will be great
Author
Owner

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

stuck in the splash screen forever, aka not working.

OK, I didn't open the app... I would guess the crypto does not exist in the native app. I might double check it...

<!-- gh-comment-id:3284286532 --> @himself65 commented on GitHub (Sep 12, 2025): > **stuck in the splash screen** forever, aka not working. OK, I didn't open the app... I would guess the crypto does not exist in the native app. I might double check it...
Author
Owner

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

OK, everyone is mentioning the react-native-webcrypto, so I forgot to do the basic check...

react-native-webcrypto was updated in 2018. It doesn't work, but it does what it expects. So I find the document, you will need expo-standard-web-crypto and expo-crypto in the repo.

Please do npx expo install expo-crypto expo-standard-web-crypto

and add polyfill on the top level

import { polyfillWebCrypto } from 'expo-standard-web-crypto';

polyfillWebCrypto();

:)

<!-- gh-comment-id:3284336659 --> @himself65 commented on GitHub (Sep 12, 2025): OK, everyone is mentioning the `react-native-webcrypto`, so I forgot to do the basic check... react-native-webcrypto was updated in 2018. It doesn't work, but it does what it expects. So I find the document, you will need `expo-standard-web-crypto` and `expo-crypto` in the repo. Please do ` npx expo install expo-crypto expo-standard-web-crypto` and add polyfill on the top level ```ts import { polyfillWebCrypto } from 'expo-standard-web-crypto'; polyfillWebCrypto(); ``` :)
Author
Owner

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

LMK if it's still not working. I can't check it; Expo build is too heavy. I don't have an Apple paid developer account, and I don't have an Android phone either. :(

If it does work, our document also needsto be update (PR is welcome) 😄

<!-- gh-comment-id:3284342292 --> @himself65 commented on GitHub (Sep 12, 2025): LMK if it's still not working. I can't check it; Expo build is too heavy. I don't have an Apple paid developer account, and I don't have an Android phone either. :( If it does work, our document also needsto be update (PR is welcome) 😄
Author
Owner

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

Or from Discord channel:

import * as ExpoeCrypto from 'expo-crypto';

if (typeof global.crypto === 'undefined') {
  global.crypto = {};
}

global.crypto.getRandomValues = ExpoeCrypto.getRandomValues;
global.crypto.randomUUID = ExpoeCrypto.randomUUID;

if (typeof globalThis !== 'undefined') {
  globalThis.crypto = global.crypto;
}

It's actually the same code...

I think if this still doesn't help, maybe you didn't put the code on the top level.

<!-- gh-comment-id:3284373058 --> @himself65 commented on GitHub (Sep 12, 2025): Or from Discord channel: ```ts import * as ExpoeCrypto from 'expo-crypto'; if (typeof global.crypto === 'undefined') { global.crypto = {}; } global.crypto.getRandomValues = ExpoeCrypto.getRandomValues; global.crypto.randomUUID = ExpoeCrypto.randomUUID; if (typeof globalThis !== 'undefined') { globalThis.crypto = global.crypto; } ``` It's actually the same code... I think if this still doesn't help, maybe you didn't put the code on the top level.
Author
Owner

@terijaki commented on GitHub (Sep 12, 2025):

@himself65 the problem is not the crypto module. I think a lot of confusion comes from dosubot's suggestions.
Noteworthy are the related issues #4496 and #4510.

#4510 is closer to the root cause of the issue.

The key are errors such as this:

The package at "node_modules/jose/dist/node/cjs/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".
It failed because the native React runtime does not include the Node standard library.

Another source of confusion might be client vs server. @better-auth/expo is needed for both.
On the server there is no issue, since people are likely running it with node or node compatible.
For the client this is causing the problems in this and the linked issues.

I got around this, not with any weird polyfill but only by rolling back @better-auth/expo and better-auth to 1.3.7.
From what I can tell this is not related to expo but rather jose or noble.

UPDATE: After a fresh install the issue seems resolved. I suggest removing node_modules and the lockfile, then reinstalling.

<!-- gh-comment-id:3284418442 --> @terijaki commented on GitHub (Sep 12, 2025): @himself65 the problem is not the crypto module. I think a lot of confusion comes from **dosubot**'s suggestions. Noteworthy are the related issues #4496 and #4510. #4510 is closer to the root cause of the issue. The key are errors such as this: ``` The package at "node_modules/jose/dist/node/cjs/runtime/base64url.js" attempted to import the Node standard library module "node:buffer". It failed because the native React runtime does not include the Node standard library. ``` Another source of confusion might be client vs server. `@better-auth/expo` is needed for both. On the server there is no issue, since people are likely running it with node or node compatible. For the client this is causing the problems in this and the linked issues. I got around this, not with any weird polyfill but only by rolling back `@better-auth/expo` and `better-auth` to 1.3.7. From what I can tell this is not related to expo but rather jose or noble. UPDATE: After a fresh install the issue seems resolved. I suggest removing node_modules **and the lockfile**, then reinstalling.
Author
Owner

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

The package at "node_modules/jose/dist/node/cjs/runtime/base64url.js" attempted to import the Node standard library module "node:buffer".

This is a werid filepath, if you look at npm jose 6.1.0. There's no such file

<!-- gh-comment-id:3284477836 --> @himself65 commented on GitHub (Sep 12, 2025): > The package at "node_modules/jose/dist/node/cjs/runtime/base64url.js" attempted to import the Node standard library module "node:buffer". This is a werid filepath, if you look at npm jose 6.1.0. There's no such file
Author
Owner

@HoshangDEV commented on GitHub (Sep 12, 2025):

I create crypto-polyfill.js in the root of the project, and put this block of code in it:

import * as ExpoeCrypto from 'expo-crypto';

if (typeof global.crypto === 'undefined') {
  global.crypto = {};
}

global.crypto.getRandomValues = ExpoeCrypto.getRandomValues;
global.crypto.randomUUID = ExpoeCrypto.randomUUID;

if (typeof globalThis !== 'undefined') {
  globalThis.crypto = global.crypto;
}

and imported the file in the main _layout.tsx like import "@/crypto-polyfill", it would be built, and also the app opens to the login screen, but when I press login (triggering the authClient.signIn.email) or sign up (authClient.signUp.email) the app would crash immediately.

<!-- gh-comment-id:3285078594 --> @HoshangDEV commented on GitHub (Sep 12, 2025): I create `crypto-polyfill.js` in the root of the project, and put this block of code in it: ```js import * as ExpoeCrypto from 'expo-crypto'; if (typeof global.crypto === 'undefined') { global.crypto = {}; } global.crypto.getRandomValues = ExpoeCrypto.getRandomValues; global.crypto.randomUUID = ExpoeCrypto.randomUUID; if (typeof globalThis !== 'undefined') { globalThis.crypto = global.crypto; } ``` and imported the file in the main `_layout.tsx` like `import "@/crypto-polyfill"`, it would be built, and also the app opens to the login screen, but when I press login (triggering the `authClient.signIn.email`) or sign up (`authClient.signUp.email`) the app would crash immediately.
Author
Owner

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

I create crypto-polyfill.js in the root of the project, and put this block of code in it:

import * as ExpoeCrypto from 'expo-crypto';

if (typeof global.crypto === 'undefined') {
global.crypto = {};
}

global.crypto.getRandomValues = ExpoeCrypto.getRandomValues;
global.crypto.randomUUID = ExpoeCrypto.randomUUID;

if (typeof globalThis !== 'undefined') {
globalThis.crypto = global.crypto;
}
and imported the file in the main _layout.tsx like import "@/crypto-polyfill", it would be built, and also the app opens to the login screen, but when I press login (triggering the authClient.signIn.email) or sign up (authClient.signUp.email) the app would crash immediately.

Hi, can you add expo-web-browser in app.config.ts plugins?

<!-- gh-comment-id:3286833566 --> @himself65 commented on GitHub (Sep 12, 2025): > I create `crypto-polyfill.js` in the root of the project, and put this block of code in it: > > import * as ExpoeCrypto from 'expo-crypto'; > > if (typeof global.crypto === 'undefined') { > global.crypto = {}; > } > > global.crypto.getRandomValues = ExpoeCrypto.getRandomValues; > global.crypto.randomUUID = ExpoeCrypto.randomUUID; > > if (typeof globalThis !== 'undefined') { > globalThis.crypto = global.crypto; > } > and imported the file in the main `_layout.tsx` like `import "@/crypto-polyfill"`, it would be built, and also the app opens to the login screen, but when I press login (triggering the `authClient.signIn.email`) or sign up (`authClient.signUp.email`) the app would crash immediately. Hi, can you add expo-web-browser in app.config.ts plugins?
Author
Owner

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

I found the root issue that triggers this bug. #4620

<!-- gh-comment-id:3287012639 --> @himself65 commented on GitHub (Sep 12, 2025): I found the root issue that triggers this bug. #4620
Author
Owner

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

can you try v1.3.10-beta.4?

<!-- gh-comment-id:3287018736 --> @himself65 commented on GitHub (Sep 12, 2025): can you try v1.3.10-beta.4?
Author
Owner

@HoshangDEV commented on GitHub (Sep 13, 2025):

can you try v1.3.10-beta.4?

Tried "better-auth": "1.3.10-beta.4" and "@better-auth/expo": "1.3.10-beta.4" , everything works fine!

btw, you still need the polyfils.

<!-- gh-comment-id:3287707229 --> @HoshangDEV commented on GitHub (Sep 13, 2025): > can you try v1.3.10-beta.4? Tried `"better-auth": "1.3.10-beta.4"` and `"@better-auth/expo": "1.3.10-beta.4"` , everything works fine! btw, you **still need the polyfils**.
Author
Owner

@erquhart commented on GitHub (Sep 13, 2025):

@himself65 with latest beta and polyfills I still get Cannot read property 'subtle' of undefined. Downgrading back to 1.3.7 resolves.

<!-- gh-comment-id:3287787907 --> @erquhart commented on GitHub (Sep 13, 2025): @himself65 with latest beta and polyfills I still get `Cannot read property 'subtle' of undefined`. Downgrading back to 1.3.7 resolves.
Author
Owner

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

try cleanup node_modules?

<!-- gh-comment-id:3287814826 --> @himself65 commented on GitHub (Sep 13, 2025): try cleanup node_modules?
Author
Owner

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

can you try v1.3.10-beta.4?

Tried "better-auth": "1.3.10-beta.4" and "@better-auth/expo": "1.3.10-beta.4" , everything works fine!

btw, you still need the polyfils.

Yeah, we still need crypto.getRandomValue

<!-- gh-comment-id:3287815278 --> @himself65 commented on GitHub (Sep 13, 2025): > > can you try v1.3.10-beta.4? > > Tried `"better-auth": "1.3.10-beta.4"` and `"@better-auth/expo": "1.3.10-beta.4"` , everything works fine! > > btw, you **still need the polyfils**. Yeah, we still need crypto.getRandomValue
Author
Owner

@HoshangDEV commented on GitHub (Sep 13, 2025):

@himself65 with latest beta and polyfills I still get Cannot read property 'subtle' of undefined. Downgrading back to 1.3.7 resolves.

I had similar thing in another project, import the crypto-polyfill.js from both main _layout.tsx and auth-client.ts in the top of the file.

before I only imported in _layout.tsx somehow the crypto-polyfill.js did not load before the authClient, so I added the import for the auth-client.ts too, and fixed the error for me.

<!-- gh-comment-id:3288361311 --> @HoshangDEV commented on GitHub (Sep 13, 2025): > [@himself65](https://github.com/himself65) with latest beta and polyfills I still get `Cannot read property 'subtle' of undefined`. Downgrading back to 1.3.7 resolves. I had similar thing in another project, import the `crypto-polyfill.js` from both main `_layout.tsx` and `auth-client.ts` in the top of the file. before I only imported in `_layout.tsx` somehow the `crypto-polyfill.js` **did not load before the authClient**, so I added the import for the `auth-client.ts` too, and fixed the error for me.
Author
Owner

@HoshangDEV commented on GitHub (Sep 14, 2025):

Bad news, it's not working with iOS in production. heading back to 1.3.6.

when I try to authClient.signIn.email, authClient.signUp.email or just any thing with it, I will get throw error, I tracked it with sentry, and it's what I got:

Error
—
Network request failed TypeError /node_modules/whatwg-fetch/dist/fetch.umd.js reader.onerror reader.onerror(whatwg-fetch/dist/fetch.umd)

 return new Promise(function(resolve, reject) {
      reader.onload = function() {
        resolve(reader.result);
      };
      reader.onerror = function() {
>        reject(reader.error);
      };
    })
  }
  function readBlobAsArrayBuffer(blob) {
<!-- gh-comment-id:3289248548 --> @HoshangDEV commented on GitHub (Sep 14, 2025): **Bad news**, it's not working with iOS in production. heading back to 1.3.6. when I try to `authClient.signIn.email`, `authClient.signUp.email` or just any thing with it, I will get throw error, I tracked it with sentry, and it's what I got: ``` Error — Network request failed TypeError /node_modules/whatwg-fetch/dist/fetch.umd.js reader.onerror reader.onerror(whatwg-fetch/dist/fetch.umd) return new Promise(function(resolve, reject) { reader.onload = function() { resolve(reader.result); }; reader.onerror = function() { > reject(reader.error); }; }) } function readBlobAsArrayBuffer(blob) { ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#27269