During the last two weeks I have been struggling a lot trying to use a mono repositories with react-native applications. When everything seems to be solved a new problem appears. I am here trying to organize my thoughts about what I have learned, however I have my mind in circles.
First of all, it seems to be a common problem. The way react native is configured and manage dependencies seems to not be that "stable" for mono repositories. I have found some issues here, here and much more links that I have lost.
In the end, I learned about yarn workspaces, lerna, hoisting dependencies, among other techniques. When I started using a react-native application with a mono repository I got some problems in regard to hoisting depedencies and started by applying nohoistfor react-native as explained here. However, in the end it seems nohoist is not a good solution for my case, not sure.
I could get a repository working with lerna, using some internal libraries, and external libraries like react-navigation. This code is available here. Here I do not use nohoist for react-native, and make sure it is available on the root node_modules. However, while I try to use the same strategy to a bigger project I have I started to have new problems with resolving external dependencies, namely with assets for @react-navigation.
Some of the articles that has helped me and my solution so far:
- https://engineering.brigad.co/react-native-monorepos-code-sharing-f6c08172b417 (this is the one I have ended up following)
- https://medium.com/@ratebseirawan/react-native-0-63-monorepo-walkthrough-36ea27d95e26
I was not expecting this to be so hard. Mono repositories seem to work very smoothly with web projects, using react, and I was expecting to use a mono repository for a project where I am working, which currenly is composed by 3 repositories: web app, mobile app, and internal library for shared code. However, after this experience, I am not confident it will be a safe approach. I will keep working on it, and I am looking for tools like nx, which has recently started supporting react-native applications as explained here.
I have also left a question on stackoverflow here.
Published