[GH-ISSUE #1715] Expo Unable to resolve "better-auth/react" #8883

Closed
opened 2026-04-13 04:08:06 -05:00 by GiteaMirror · 10 comments
Owner

Originally created by @LeulAria on GitHub (Mar 6, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/1715

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

iOS Bundling failed 702ms node_modules/expo-router/entry.js (1122 modules)
Unable to resolve "better-auth/react" from "lib/auth-client.ts"

Image

Current vs. Expected behavior

"better-auth/react" should be imported on the lib/auth-client.ts lib

What version of Better Auth are you using?

1.2.3

Provide environment information

- OSX
- IOS Simulator Expo

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

Package

Auth config (if applicable)

import { betterAuth } from "better-auth"
export const auth = betterAuth({
  emailAndPassword: {  
    enabled: true
  },
});

Additional context

No response

Originally created by @LeulAria on GitHub (Mar 6, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/1715 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce iOS Bundling failed 702ms node_modules/expo-router/entry.js (1122 modules) Unable to resolve "better-auth/react" from "lib/auth-client.ts" ![Image](https://github.com/user-attachments/assets/4ab89f06-0122-4313-85aa-582bf47c8166) ### Current vs. Expected behavior "better-auth/react" should be imported on the lib/auth-client.ts lib ### What version of Better Auth are you using? 1.2.3 ### Provide environment information ```bash - OSX - IOS Simulator Expo ``` ### Which area(s) are affected? (Select all that apply) Package ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth" export const auth = betterAuth({ emailAndPassword: { enabled: true }, }); ``` ### Additional context _No response_
GiteaMirror added the lockedbug labels 2026-04-13 04:08:06 -05:00
Author
Owner

@sangdth commented on GitHub (Mar 8, 2025):

I think I face the same issue. If add the https://www.better-auth.com/docs/integrations/expo#configure-metro-bundler line, the app stuck at "Downloading 100%", if I remove that metro.config.js file, this red screen happens.

<!-- gh-comment-id:2708456150 --> @sangdth commented on GitHub (Mar 8, 2025): I think I face the same issue. If add the https://www.better-auth.com/docs/integrations/expo#configure-metro-bundler line, the app stuck at "Downloading 100%", if I remove that metro.config.js file, this red screen happens.
Author
Owner

@jannwitt commented on GitHub (Mar 12, 2025):

Same here! Did anyone find a solution for this?

<!-- gh-comment-id:2716852384 --> @jannwitt commented on GitHub (Mar 12, 2025): Same here! Did anyone find a solution for this?
Author
Owner

@fhorray commented on GitHub (Mar 16, 2025):

I'm having the same problem, following this issue to see if anyone come up with a solution.

<!-- gh-comment-id:2727166485 --> @fhorray commented on GitHub (Mar 16, 2025): I'm having the same problem, following this issue to see if anyone come up with a solution.
Author
Owner

@trevor-e commented on GitHub (Mar 20, 2025):

AFAICT this might be an issue with Metro/Expo? As soon as I enable config.resolver.unstable_enablePackageExports = true; in my project it starts to misbehave and gets stuck on the splash screen with no logs.

The package.json exports in the @better-auth/expo package look correct to me:

  "exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "import": "./dist/index.mjs",
      "require": "./dist/index.cjs"
    },
    "./client": {
      "types": "./dist/client.d.ts",
      "import": "./dist/client.mjs",
      "require": "./dist/client.cjs"
    }
  },

I read through the Metro docs for this feature and nothing in particular stood out.

<!-- gh-comment-id:2740781920 --> @trevor-e commented on GitHub (Mar 20, 2025): AFAICT this might be an issue with Metro/Expo? As soon as I enable `config.resolver.unstable_enablePackageExports = true;` in my project it starts to misbehave and gets stuck on the splash screen with no logs. The `package.json` exports in the `@better-auth/expo` package look correct to me: ``` "exports": { ".": { "types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs" }, "./client": { "types": "./dist/client.d.ts", "import": "./dist/client.mjs", "require": "./dist/client.cjs" } }, ``` I read through the [Metro docs](https://metrobundler.dev/docs/package-exports) for this feature and nothing in particular stood out.
Author
Owner

@iosazee commented on GitHub (Mar 21, 2025):

Try adding this setting config.resolver.unstable_conditionNames = [ "react-native", "import", "require", "browser", "types", ];; immediately after the config.resolver.unstable_enablePackageExports = true;. See if that fixes the issue

<!-- gh-comment-id:2743589438 --> @iosazee commented on GitHub (Mar 21, 2025): Try adding this setting `config.resolver.unstable_conditionNames = [ "react-native", "import", "require", "browser", "types", ];;` immediately after the `config.resolver.unstable_enablePackageExports = true;`. See if that fixes the issue
Author
Owner

@hyoban commented on GitHub (Mar 22, 2025):

Has anyone tried using babel-plugin-module-resolver? It works fine for me.

https://www.better-auth.com/docs/integrations/expo#configure-metro-bundler

<!-- gh-comment-id:2744946208 --> @hyoban commented on GitHub (Mar 22, 2025): Has anyone tried using babel-plugin-module-resolver? It works fine for me. https://www.better-auth.com/docs/integrations/expo#configure-metro-bundler
Author
Owner

@trevor-e commented on GitHub (Mar 22, 2025):

@hyoban are you trying in a freshly created project? The babel-plugin-module-resolver isn't working for me. First it complains about caching not being enabled. After enabling caching it complains about JSX not being recognized. After adding presets: ['@babel/preset-react'] to my Babel config it starts throwing random errors like this:

iOS Bundling failed 3099ms node_modules/expo-router/entry.js (907 modules)
 ERROR  SyntaxError: /Users/telkins/dev/telkins/my-proj/app-expo/node_modules/@expo/metro-runtime/src/async-require/buildAsyncRequire.ts: Missing semicolon. (14:4)

🤯

<!-- gh-comment-id:2745910215 --> @trevor-e commented on GitHub (Mar 22, 2025): @hyoban are you trying in a freshly created project? The `babel-plugin-module-resolver` isn't working for me. First it complains about caching not being enabled. After enabling caching it complains about JSX not being recognized. After adding `presets: ['@babel/preset-react']` to my Babel config it starts throwing random errors like this: ``` iOS Bundling failed 3099ms node_modules/expo-router/entry.js (907 modules) ERROR SyntaxError: /Users/telkins/dev/telkins/my-proj/app-expo/node_modules/@expo/metro-runtime/src/async-require/buildAsyncRequire.ts: Missing semicolon. (14:4) ``` 🤯
Author
Owner

@hyoban commented on GitHub (Mar 22, 2025):

I didn't know it would happen yet, I'll try it and see

<!-- gh-comment-id:2745913718 --> @hyoban commented on GitHub (Mar 22, 2025): I didn't know it would happen yet, I'll try it and see
Author
Owner

@hyoban commented on GitHub (Mar 24, 2025):

A minimal usable configuration is as follows

module.exports = function (api) {
  api.cache(true);
  return {
    presets: ["babel-preset-expo"],
    plugins: [
      [
        "module-resolver",
        {
          alias: {
            "better-auth/react":
              "./node_modules/better-auth/dist/client/react/index.cjs",
            "better-auth/client/plugins":
              "./node_modules/better-auth/dist/client/plugins/index.cjs",
            "@better-auth/expo/client":
              "./node_modules/@better-auth/expo/dist/client.cjs",
          },
        },
      ],
    ],
  };
};
<!-- gh-comment-id:2747224635 --> @hyoban commented on GitHub (Mar 24, 2025): A minimal usable configuration is as follows ```js module.exports = function (api) { api.cache(true); return { presets: ["babel-preset-expo"], plugins: [ [ "module-resolver", { alias: { "better-auth/react": "./node_modules/better-auth/dist/client/react/index.cjs", "better-auth/client/plugins": "./node_modules/better-auth/dist/client/plugins/index.cjs", "@better-auth/expo/client": "./node_modules/@better-auth/expo/dist/client.cjs", }, }, ], ], }; }; ``` - https://docs.expo.dev/versions/latest/config/babel
Author
Owner

@trevor-e commented on GitHub (Mar 24, 2025):

This worked, thanks so much @hyoban! Sorry didn't realize there is an Expo preset I was supposed to use.

<!-- gh-comment-id:2748580419 --> @trevor-e commented on GitHub (Mar 24, 2025): This worked, thanks so much @hyoban! Sorry didn't realize there is an Expo preset I was supposed to use.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#8883