Skip to content

Commit 35c831b

Browse files
chriscanindstaley
andauthored
fix(clerk-expo): Resolve module loading issue for optional Sign in with Apple (#7171)
Co-authored-by: Dylan Staley <88163+dstaley@users.noreply.github.com>
1 parent 9abb76f commit 35c831b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@clerk/clerk-expo': patch
3+
---
4+
5+
Fix module resolution error for users not using Sign in with Apple by removing static imports of `expo-apple-authentication` and `expo-crypto`, replacing them with dynamic imports that only load when the `useSignInWithApple()` hook is actually called.

packages/expo/src/hooks/useSignInWithApple.ios.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import { useSignIn, useSignUp } from '@clerk/clerk-react';
22
import type { SetActive, SignInResource, SignUpResource } from '@clerk/types';
3-
import * as AppleAuthentication from 'expo-apple-authentication';
4-
import * as Crypto from 'expo-crypto';
53

64
import { errorThrower } from '../utils/errors';
75

@@ -69,6 +67,19 @@ export function useSignInWithApple() {
6967
};
7068
}
7169

70+
// Dynamically import expo-apple-authentication only when needed
71+
let AppleAuthentication;
72+
let Crypto;
73+
74+
try {
75+
[AppleAuthentication, Crypto] = await Promise.all([import('expo-apple-authentication'), import('expo-crypto')]);
76+
} catch {
77+
return errorThrower.throw(
78+
'expo-apple-authentication is required to use Sign in with Apple. ' +
79+
'Please install it by running: npx expo install expo-apple-authentication expo-crypto',
80+
);
81+
}
82+
7283
// Check if Apple Authentication is available on the device
7384
const isAvailable = await AppleAuthentication.isAvailableAsync();
7485
if (!isAvailable) {

0 commit comments

Comments
 (0)