iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🪤

Two Traps in Expo SDK 55 Upgrade: fullScreenModal Freezing and pnpm Hoisting

に公開

Introduction

In a project managing multiple Expo apps within a pnpm monorepo, I upgraded from Expo SDK 53/54 to 55. After resolving dependencies with npx expo install --fix, I encountered two critical issues during real-device testing.

Monorepo Structure

monorepo/
├── apps/
│   ├── app-a/          # Expo SDK 53 → 55
│   └── app-b/          # Expo SDK 54 → 55
├── packages/
│   └── shared-types/   # Shared type definitions
├── services/
│   ├── backend/        # Express API
│   └── functions/      # Cloud Functions
├── pnpm-workspace.yaml
└── .npmrc              # node-linker=hoisted

Issue 1: App freezes with fullScreenModal

Symptoms

When closing a modal screen (presentation: 'fullScreenModal'), the entire app freezes and becomes unresponsive. It is not a crash; the screen simply locks up. No errors appear in the console.

// _layout.tsx
<Stack.Screen
  name="practice-session"
  options={{
    presentation: 'fullScreenModal',  // ← This is the cause
    headerShown: false,
  }}
/>

Investigation Process

Initially, I suspected the components inside the modal (audio service stop processing, router's back() vs dismiss()), but those were false leads.

Created a minimal test screen for isolation:

// test-screen.tsx — A screen with only a close button
export default function TestScreen() {
  const router = useRouter();
  return (
    <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
      <Button title="Close" onPress={() => router.back()} />
    </View>
  );
}

Even with this minimal screen, the freeze occurred when opened as fullScreenModal → Confirmed as an issue with the navigation layer, not the component.

Then, I changed presentation to 'card', and the freezing stopped.

Cause

There is a bug in the dismiss processing of fullScreenModal when using react-native-screens 4.23 + New Architecture (Fabric).

In Expo SDK 55, the Legacy Architecture has been completely removed, forcing the use of the New Architecture. Since the Legacy Architecture was the default in SDK 54 and earlier, this issue did not manifest previously.

Fix

Replace fullScreenModal with card + slide_from_bottom animation. The appearance is almost identical.

 <Stack.Screen
   name="practice-session"
   options={{
-    presentation: 'fullScreenModal',
+    presentation: 'card',
+    animation: 'slide_from_bottom',
     headerShown: false,
+    gestureEnabled: false,
   }}
 />

If you don't need the vertical slide animation (like on a sign-in screen), you can also use the fade animation.

 <Stack.Screen
   name="signin"
   options={{
-    presentation: 'fullScreenModal',
+    presentation: 'card',
+    animation: 'fade',
     gestureEnabled: false,
   }}
 />

Issue 2: "cannot find native module" error due to pnpm hoisting

Symptoms

When building and starting app-a, the following errors occur repeatedly:

Uncaught Error: Cannot find native module 'ExpoStoreReview'
Uncaught Error: Cannot find native module 'ExpoImage'
Uncaught Error: Cannot find native module 'ExpoDevClient'
...

app-a does not even use expo-store-review or expo-image. These are dependency packages for app-b.

Cause

Due to the node-linker=hoisted setting in pnpm, the dependencies of app-b are hoisted to the root node_modules.

monorepo/
├── node_modules/
│   ├── expo-store-review/   ← Hoisted to root as a dependency of app-b
│   ├── expo-image/          ← Same as above
│   └── expo-dev-client/     ← Same as above
├── apps/
│   ├── app-a/               ← Does not use expo-store-review
│   └── app-b/               ← Uses expo-store-review

Expo's autolinking system scans the root node_modules and attempts to include these in the native binary for app-a as well. While you can exclude these on the native side using autolinking.exclude, this does not prevent Metro bundler's JS resolution.

Fix: Two-layered approach

Step 1: autolinking.exclude (Native side)

// apps/app-a/package.json
{
  "expo": {
    "autolinking": {
      "exclude": [
        "expo-store-review",
        "expo-dev-client",
        "expo-image"
      ]
    }
  }
}

Step 2: Metro resolveRequest (JS side)

// apps/app-a/metro.config.js
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);

// Block hoisted packages from other apps
const blockedModules = [
  'expo-store-review',
  'expo-dev-client',
  'expo-image',
  '@expo/ui',
];

const originalResolveRequest = config.resolver.resolveRequest;
config.resolver.resolveRequest = (context, moduleName, platform) => {
  if (blockedModules.some(
    (blocked) => moduleName === blocked || moduleName.startsWith(blocked + '/')
  )) {
    return { type: 'empty' };
  }
  if (originalResolveRequest) {
    return originalResolveRequest(context, moduleName, platform);
  }
  return context.resolveRequest(context, moduleName, platform);
};

module.exports = config;

Step 3: Clean prebuild

After modifying autolinking.exclude, always perform a clean prebuild. This is because the existing ExpoModulesProvider.swift retains the old settings.

npx expo prebuild --clean --platform ios
How to verify ExpoModulesProvider.swift

After prebuild, check the following file to see which modules are linked natively:

# iOS
cat ios/Pods/Target\ Support\ Files/Pods-YourApp/ExpoModulesProvider.swift

# Confirm that excluded modules are not included
grep -E "StoreReview|DevClient|ExpoImage" ios/Pods/.../ExpoModulesProvider.swift

Summary

Issue Cause Fix
Freeze with fullScreenModal react-native-screens 4.23 + New Architecture Replace with card + slide_from_bottom
Native module error for other apps pnpm hoisting + Expo autolinking autolinking.exclude + Metro resolveRequest

Learnings

  1. Expo SDK 55 = Forced New Architecture. The Legacy Architecture has been removed, so previously working code may break.
  2. Isolate with minimal reproduction. The fullScreenModal issue was identified in 5 minutes by creating an empty test screen.
  3. autolinking.exclude is insufficient for pnpm monorepos. You must also block the JS side via Metro's resolveRequest.
  4. Read ExpoModulesProvider.swift. It tells you at a glance which modules are linked natively.

Debugging Checklist

  • Check if any screens use fullScreenModal (may break in SDK 55)
  • Run npx expo prebuild --clean to regenerate ExpoModulesProvider
  • Check if dependencies of other apps are hoisted in the pnpm monorepo (ls node_modules | grep expo-)
  • Verify that a blocklist is set in Metro config's resolveRequest
GitHubで編集を提案

Discussion