How to run Expo and React Native in a pnpm monorepo.
Here are notes of all the difficulties encountered:
- Expo v42 - pnpm/pnpm#3731
- React Native v0.65 - pnpm/pnpm#3740
Ensure watchman
is installed.
pnpm i
cd packages/expo-42
npm run ios
cd packages/react-native-v65
npm run start
npm run ios
- We replace Metro's resolver with
webpack/enhanced-resolve
using theresolveRequest
config option. - We patch
metro
to fix ajest-haste-map
issue.
enhanced-resolve
is super slow, so we use theunsafeCache
option and write this to disk.- Loading the initial Metro dep graph takes a long time in large monorepos but this usually only has to be done once. I think it involves reading all files in your monorepo. I think this data is cached to
node_modules/.cache/metro-custom
. It would be nice to share this cache if possible across multiple mobile apps.
-
Don't forget to apply
package.json#pnpm.overrides
to the root of your project. (This could also be done in thepnpmfile.js
.) -
Make sure to add the
pnpmfile.js
lines.
Be careful of this issue when using pnpmfiles and pnpm update
after updating a pnpmfile
.
EXPO_RESOLVE_PROGRESS=1 npm run ios
rm -rf packages/expo/node_modules/.cache
watchman watch-del-all
cd packages/expo
pnpm why metro
# Ensure there are NO results
pnpm why @vjpr/metro
# Ensure there are results
This can fix bad dependency issues and will also solve pnpm/pnpm#3735
npm run delete-node-modules
pnpm i
- Maybe we don't need to patch
metro
, and we just patchjest-haste-map
becausepnpm.overrides
is smarter now.
For latest RN I think the issue is fixed anyway.
- Share the metro dep graph cache across projects.