Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-expo-apple-auth-optional.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/clerk-expo': patch
---

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.
15 changes: 13 additions & 2 deletions packages/expo/src/hooks/useSignInWithApple.ios.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { useSignIn, useSignUp } from '@clerk/clerk-react';
import type { SetActive, SignInResource, SignUpResource } from '@clerk/types';
import * as AppleAuthentication from 'expo-apple-authentication';
import * as Crypto from 'expo-crypto';

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

Expand Down Expand Up @@ -69,6 +67,19 @@ export function useSignInWithApple() {
};
}

// Dynamically import expo-apple-authentication only when needed
let AppleAuthentication;
let Crypto;

try {
[AppleAuthentication, Crypto] = await Promise.all([import('expo-apple-authentication'), import('expo-crypto')]);
} catch {
return errorThrower.throw(
'expo-apple-authentication is required to use Sign in with Apple. ' +
'Please install it by running: npx expo install expo-apple-authentication expo-crypto',
);
}

// Check if Apple Authentication is available on the device
const isAvailable = await AppleAuthentication.isAvailableAsync();
if (!isAvailable) {
Expand Down