Detect duplicate packages in node_modules caused by hoisting issues
Orkhan Alikhanov
## Summary
expo-doctor
should detect when the same package exists multiple times in node_modules
at different paths (e.g. node_modules/@react-navigation/native
and node_modules/expo-router/node_modules/@react-navigation/native
), even when they resolve to the same version.## Problem
After upgrading from Expo SDK 55 beta to stable, I hit this runtime error:
Error: Couldn't find the prevent remove context. Is your component inside NavigationContent?
The root cause was
@react-navigation/native
being installed twice — once at the root and once nested inside expo-router/node_modules
. Even though both resolved to the same version (7.1.34
), they created separate React contexts, breaking navigation.This was caused by a package manager hoisting issue (bun in my case) and was fixed by a clean
rm -rf node_modules && bun install
. The issue was hard to diagnose because:- expo-doctorreported no problems
- The versions matched, so version-based checks wouldn't catch it
- The error message pointed to a missing context, not a duplicate package
## Proposed check
Add a check that scans for packages that appear at multiple paths in
node_modules
(particularly React/React Native ecosystem packages where duplicate instances break context sharing). When detected, suggest a clean reinstall.