Skip to content

Commit 109bb48

Browse files
committed
fix(expo): Load SSO deps via require() to fix Metro async-chunk failure
1 parent da93ece commit 109bb48

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/expo': patch
3+
---
4+
5+
Load `expo-auth-session` and `expo-web-browser` in `useSSO` via synchronous `require()` instead of dynamic `import()`, which fails to resolve under Metro when `@expo/metro-runtime` is not set up at the app entry.

packages/expo/src/hooks/useSSO.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,22 @@ export function useSSO() {
4747
};
4848
}
4949

50-
// Dynamically import expo-auth-session and expo-web-browser only when needed
51-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- dynamic import of optional dependency
50+
// Load via synchronous require() instead of import(): Metro inlines require() into the main
51+
// bundle, while import() emits an async chunk that fails to resolve without @expo/metro-runtime.
52+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- type-only annotation for optional dependency
5253
let AuthSession: typeof import('expo-auth-session');
53-
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- dynamic import of optional dependency
54+
// eslint-disable-next-line @typescript-eslint/consistent-type-imports -- type-only annotation for optional dependency
5455
let WebBrowserModule: typeof import('expo-web-browser');
5556
try {
56-
[AuthSession, WebBrowserModule] = await Promise.all([import('expo-auth-session'), import('expo-web-browser')]);
57-
} catch {
57+
// eslint-disable-next-line @typescript-eslint/no-require-imports
58+
AuthSession = require('expo-auth-session');
59+
// eslint-disable-next-line @typescript-eslint/no-require-imports
60+
WebBrowserModule = require('expo-web-browser');
61+
} catch (err) {
5862
return errorThrower.throw(
59-
'expo-auth-session and expo-web-browser are required for SSO. ' +
60-
'Install them: npx expo install expo-auth-session expo-web-browser',
63+
'Unable to load expo-auth-session and expo-web-browser, which are required for SSO. ' +
64+
'If they are not installed, run: npx expo install expo-auth-session expo-web-browser. ' +
65+
`Original error: ${err instanceof Error ? err.message : String(err)}`,
6166
);
6267
}
6368

0 commit comments

Comments
 (0)