byCedric / expo-monorepo-example

Fast pnpm monorepo for cross-platform apps built with Expo / React Native and React.
https://docs.expo.dev/guides/monorepos/
MIT License
724 stars 76 forks source link

Linking dependencies is not working correctly for managed apps #22

Closed jovanbaj closed 3 years ago

jovanbaj commented 3 years ago

Description of the bug

Linking dependencies from different packages seems to be broken.

To Reproduce

I am using react-native-svg dependency in a different package and using it in my package where my app is. When doing eas build for android, everything passes, but I get the Invariant Violation: "RNSVGPath" was not found in the UIManager. Digging into the build process for android, it doesn't build it unless I put the dependency in the same package as my app. This is not just with react-native-svg, I am using it for the quickest reproduction.

Expected behavior

To link the dependency and install it for the native use.

Actual behavior

Ignores the dependency and runs the build without it.

Additional context

I am not 100% clear on linking dependencies. I have similar setup as you made it here (with-sentry). It's a managed workflow and a monorepo. Using symlinks was working on android before, but I wanted to move away from that. Happy to provide all the extra info that you need and my apologies if this is the wrong place for this kind of issue.

byCedric commented 3 years ago

Hi @jovanbaj! Unfortunately, this is not something we can fix (easily). It's one of the limitations of React Native's own autolinking. Brent mentions this in our newer Expo modules blog post:

Do you remember the react-native link CLI command? 🤔

With react-native-unimodules we introduced the idea of "autolinking" to reduce the hassle of installing and setting up native modules, and this inspired a similar implementation in @react-native-community/cli.

A key difference in our implementation is that we link transitive dependencies (dependencies of dependencies), whereas the @react-native-community/cli implementation links only those libraries that are explicitly listed in your package.json.

Our autolinking implementation wasn’t designed to support monorepos (remember, this was 2018) and so developers had to work around this by symlinking hoisted packages (which we helped out with through expo-yarn-workspaces). A better solution was needed, in particular because this required some manual configuration after running expo prebuild in a managed project — so it can be tricky to get managed app monorepos running on EAS Build.

Because react-native-svg isn't a package made with unimodules or Expo modules, it uses the React Native autolinking instead of Expo autolinking, and that does not support dependencies of dependencies. Symlinking it into the app's node_modules might have tricked React Native's autolinking to link it.

I think the easiest solution is to add it as dependency to your package.json.