Title: @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript · GitHub
Open Graph Title: @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript
X Title: @clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch · Issue #8288 · clerk/javascript
Description: Summary useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when @expo/metr...
Open Graph Description: Summary useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in m...
X Description: Summary useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon ...
Opengraph URL: https://github.com/clerk/javascript/issues/8288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"@clerk/expo: useSSO/useOAuth dynamic import() of expo-auth-session/expo-web-browser fails under Metro, masked by empty catch","articleBody":"## Summary\n\n`useSSO` / `useOAuth` in `@clerk/expo` use a dynamic `import()` for `expo-auth-session` and `expo-web-browser` wrapped in an empty `catch {}`. When Metro's async-chunk resolution fails (not uncommon in monorepo / bun setups, or when `@expo/metro-runtime` isn't imported at the entry), every underlying error is swallowed and surfaces as the misleading:\n\n> expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser\n\n…even though both packages are installed, listed in `package.json`, and being bundled by Metro.\n\n## Offending code\n\n`packages/expo/src/hooks/useSSO.ts` (built as `dist/hooks/useSSO.js`):\n\n```js\nlet AuthSession;\nlet WebBrowserModule;\ntry {\n [AuthSession, WebBrowserModule] = await Promise.all([\n import(\"expo-auth-session\"),\n import(\"expo-web-browser\"),\n ]);\n} catch {\n return errorThrower.throw(\n \"expo-auth-session and expo-web-browser are required for SSO. Install them: npx expo install expo-auth-session expo-web-browser\"\n );\n}\n```\n\nTwo problems:\n\n1. **Dynamic `import()` from a published bundle is fragile under Metro.** It forces Metro to emit async chunks; if the runtime loader isn't set up (e.g. `@expo/metro-runtime` not imported), the promise rejects and the real error never surfaces. A synchronous `require()` would be bundled into the main chunk and \"just work\". This is the same class of issue fixed for the RN QueryClient in clerk/javascript#8087 — dynamic import from inside the published bundle broken under Metro, sync setup resolves it.\n2. **`catch {}` hides the real error.** Even when the underlying failure is `Unable to resolve module`, `@expo/metro-runtime is not installed`, or a genuine `TypeError`, users see a generic \"install these packages\" message that sends them in the wrong direction.\n\n## Environment\n\n- `@clerk/expo@3.1.9`\n- Expo SDK 55 (`expo@^55.0.11`, `expo-router@~55.0.10`)\n- Metro (default `@expo/metro-config`)\n- `expo-auth-session@~55.0.13`, `expo-web-browser@~55.0.14` both installed\n- bun workspaces monorepo\n- iOS (dev client + simulator)\n\n## Repro\n\n1. Bun-workspaces monorepo, `@clerk/expo` + `expo-auth-session` + `expo-web-browser` all correctly declared in `apps/mobile/package.json`.\n2. Don't import `@expo/metro-runtime` at the entry (it's not a declared dep of `@clerk/expo` or `expo-router` in this setup, so it's easy to miss).\n3. Call `startSSOFlow({ strategy: 'oauth_google' })` from a screen.\n4. Metro logs show both packages bundling successfully:\n\n ```\n iOS Bundled 321ms …/expo-auth-session/build/index.js (1018 modules)\n iOS Bundled 347ms …/expo-web-browser/build/WebBrowser.js (1145 modules)\n ```\n\n5. At runtime, the dynamic `import()` inside `useSSO` rejects and Clerk throws the \"required for SSO\" error.\n\nRoot cause in our case: `@expo/metro-runtime` wasn't imported at the app entry, so async chunks produced by Metro couldn't be loaded. Adding `import '@expo/metro-runtime'` at the top of the root layout fixed the runtime loading — but only after hours of wrong turns because the Clerk error pointed at package installation, not bundler/runtime.\n\n## Current workaround\n\nWe ship a `postinstall` patch that rewrites the dynamic imports to `require()`:\n\n```js\n// scripts/patch-clerk-expo-sso.mjs\nconst SNIPPET_FROM =\n '[AuthSession, WebBrowserModule] = await Promise.all([import(\"expo-auth-session\"), import(\"expo-web-browser\")]);';\nconst SNIPPET_TO = `AuthSession = require(\"expo-auth-session\");\n WebBrowserModule = require(\"expo-web-browser\");`;\n```\n\nApplied to `node_modules/@clerk/expo/dist/hooks/useSSO.js` and `useOAuth.js`. This eliminates the problem entirely on native because Metro inlines both modules into the main bundle instead of emitting async chunks.\n\n## Proposed fix\n\nEither (or both):\n\n1. **Prefer synchronous `require()` on native** (same spirit as clerk/javascript#8087). `expo-auth-session` / `expo-web-browser` are tiny and already listed as optional peer deps — nothing is gained by deferring them. `require()` is Metro-safe and removes the async-chunk failure mode entirely.\n\n2. **At minimum, surface the real error:**\n\n ```js\n try {\n [AuthSession, WebBrowserModule] = await Promise.all([\n import(\"expo-auth-session\"),\n import(\"expo-web-browser\"),\n ]);\n } catch (e) {\n return errorThrower.throw(\n \\`expo-auth-session and expo-web-browser are required for SSO. If they are installed, this usually means Metro failed to resolve the dynamic import() — ensure \\\\\\`@expo/metro-runtime\\\\\\` is imported at your app entry. Underlying error: \\${e?.message ?? e}\\`\n );\n }\n ```\n\n The `catch {}` is actively hostile to debugging — it converts every possible failure mode (bundler, runtime, native module, version mismatch) into a single wrong-suggestion error.\n\nHappy to open a PR if the direction is agreed.\n\n## Related\n\n- clerk/javascript#8087 — `fix(expo): synchronous QueryClient for React Native` (same class of dynamic-import-in-Metro fix)","author":{"url":"https://github.com/sethwebster","@type":"Person","name":"sethwebster"},"datePublished":"2026-04-11T03:48:24Z","url":"https://github.com/clerk/javascript/issues/8288"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b94e5a93-5fe0-543d-d62f-79abe260c9f9 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E1C0:3D6EF:7FC6B8:B400E2:6AFB6CF8 |
| html-safe-nonce | e8e9d5a3de39d741622029ed32506659ced7b7df79db841a0f24bb48ee1a0957 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMUMwOjNENkVGOjdGQzZCODpCNDAwRTI6NkFGQjZDRjgiLCJ2aXNpdG9yX2lkIjoiNTcwNjIyMDYzMTMwNTcxMDg0MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | cbe95bbe27dda871a27b0b192ad0d1e18a6f02a2c02eeb84422ea20669f9d8f2 |
| hovercard-subject-tag | issue:4242926656 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/clerk/javascript/8288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7e64782e6707c0e0e193c9a7d23a8e8d3651a37a8ec4e32891bea4c4b031a59f/clerk/javascript/issues/8288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7e64782e6707c0e0e193c9a7d23a8e8d3651a37a8ec4e32891bea4c4b031a59f/clerk/javascript/issues/8288 |
| og:image:alt | Summary useSSO / useOAuth in @clerk/expo use a dynamic import() for expo-auth-session and expo-web-browser wrapped in an empty catch {}. When Metro's async-chunk resolution fails (not uncommon in m... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sethwebster |
| hostname | github.com |
| expected-hostname | github.com |
| None | cca289ecd54650fcf3c0b037a58b97186dee2cc4406819d87fab93728fd83700 |
| turbo-cache-control | no-preview |
| go-import | github.com/clerk/javascript git https://github.com/clerk/javascript.git |
| octolytics-dimension-user_id | 49538330 |
| octolytics-dimension-user_login | clerk |
| octolytics-dimension-repository_id | 438331492 |
| octolytics-dimension-repository_nwo | clerk/javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 438331492 |
| octolytics-dimension-repository_network_root_nwo | clerk/javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 88808b1fae5ab8a526a73e7ce5542a10eb9d6971 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width