-
Notifications
You must be signed in to change notification settings - Fork 890
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Struggling to set up a monorepo with 2 RN apps and a shared package that includes native code #826
Comments
Update, added a single-native-app monorepo that breaks when I include a native module (react-native-add-calendar-event, in this case) https://github.com/maxkorp/my-new-monorepo This works (mostly) with iOS. Just I modifed the root level native_modules.gradle (at Also of note that metro starts in the wrong directory (for both ios and android), but if I also run |
Aha! So it turns out the jetifier runs automatically, but is not finding the modules at the root directory; |
Hey, Thanks for deep explanation of your issue. Please run As a principle, you should always run the CLI from the root of your React Native project (especially, when you have multiple React Native projects). Are you using Yarn Workspaces? If not, you should, and each package that references React Native should have it as its dependency. I suspect that React Native lives at the root of your monorepo, which is good. CLI shouldn't have issues finding and linking things in such scenario, so I guess we have a small configuration issue to resolve. (PS. Updating paths a bit is a normal thing to do, so don't worry. Ideally, I'd like to replace paths with React Native CLI calls so you dont have to update that). |
Thanks for getting back to me! So we do use yarn workspaces sortof , but due to how we have our bucklescript setup, we can't really do the dependency thing where moduleA uses moduleB so it has moduleB in it's dependencies and it gets linked in (the ocaml compiler doesn't work with the symlinks, everything is compiled in place basically eg I have a bunch of new notes on this as we've found stuff. Currently we have almost working with some hackery, except for loading images out of hoisted node_modules on ios only during production builds. I'll try to write everything up today and update the example repo |
So there are currently a few issues. A lot of this is metro related I suspect more than anything else, but I don't know how much of it is something to resolve here in the meantime. At least one or two issues are with scripts from If you would like me to make individual issues for any or all of these, or file issues against other projects (like react-native or metro), just let me know and I am happy to do so! Or if you need any help digging into this all, I can make myself available at any time of day (IIRC You are in Europe, I can sync up with you during your workday). I'm also happy to crank on the tooling and submit PRs if you know which direction you want to go on things.
Do you mean in this case the root of the monorepo, or the specific workspace? We've been always doing it from the workspace (e.g. I've attached the output of Here are all of the issues i've found trying to get things set up, that aren't as simple as changing some paths. Jetifier does not get run at the root properlyThis is the actual cause of the issue described here: #826 (comment). It seems like it runs jetify inside the rn project workspace, so no node_modules get found (since they're all hoisted to the monorepo root), Once I run Metro gets started in the wrong place and does not pick up the configIn the "start packager" step in xcode (I forget where it happens for android, somewhere in I've solved this for now by duplicating that file into my project, and adding a CD to the project directory first.
Not ideal, but it works. perhaps files loaded out of node_modules or shared get paths messed up on androidI found an issue about this in metro (I can't find it now), it seems okhttp resolves relative paths away before making requests (e.g. assets/../shared-mobile/someFile gets loaded as I fixed this in a bit of a hack by adding the root of my monorepo as well as the packages folder to the metro config search directories. platform specific images do not resolve out if
|
Thank you for sending this! I will look into it this week. There's some valid points here and I'd like to take some time to understand it and see if there's anything we can do to improve your DX. Appreciate time put into describing this. |
Sure thing! Please let me know if you have any questions or need me to try anything! |
check this thread https://twitter.com/sseraphini/status/1202217314638282752 the example repo is here |
@sibelius Does your repo structure have the issue mentioned above: |
everything is working fine for us |
@Minishlink were you able to solve? Experiencing the same issue with assets. |
I think we got some problems with assets in both android and iOS IOS works well in dev mode, but android and iOS file to show images |
@sibelius In DEV mod is OK. The problem is on release mode the assets got messed up as @Minishlink said |
Here's a probable workaround, make sure you have the same cli and RN version. I don't give any warranty on this. If you use this, test it thoroughly in debug/release mode on Android/iOS. Also make sure to understand how patch-package work. https://gist.github.com/Minishlink/14fde025b4352d0802e25e098e357046 |
Here is an example repo I set up that shows what we've done to get things working https://github.com/maxkorp/codepush-monorepo-example. There are some commits on master that are related to similar issues for codepush, but you can go back to the second commit to see how I got things working. |
@Wellers0n autolinking only works in the direct RN app dependencies - you'll need native modules to be nohoist-ed dependencies of the app directly as well as the global package. |
assets are still broken on production mode is there a workaround for this? for instance, if you use react-navigation the hamburger menu will be missing in the prod version |
it works on rn 63 |
Ask your Question
Sorry for the impending wall of text, and thank you in advance for any help.
I have a monorepo (using yarn workspaces) that has several non-rn apps (a graphql server, 2 different websites, others) and as of now a single react-native ios/android app. This works by just nohoisting everything RN related, and some metro config to make sure it can find the js in the other packages. Everything related I've found (mostly issues in this repo, honestly) is more about getting a single RN app to work in a monorepo.
I'm looking for help with configuring everything to make this work. This is rapidly approaching being a blocker for some of my team, so I can definitely dedicate some decent time to working on cli if needed. My native-fu is somewhat weak, but I'm happy to jump in if I can get some some guidance. I am flexible.
Here is my desired project structure:
Currently, it's basically the same as that except that there is only one mobile app, and the shared-mobile folder doesn't reference any native code.
We're trying to add a second RN android/ios app to the mix. Currently we have a single shared folder for stuff accessible everywhere. I'm first trying to get the single app to work with the native code hoisted, since that seems prerequisite to the shared code being able to be hoisted. Assuming that works, I'd be able to get stuff working by not having any shared native code, but this involves a ton of code duplication with tedious reference changes.
Ideally, we'd like to add the majority of the native stuff to our shared-mobile folder. I was able to get IOS to work with a bit of a hack, but I've been unable to get android working. I've been trying both with what ships with RN 0.61.2, as well as upgrading the cli to the latest 3 alpha (7?).
For the ioS stuff, to get it working, I simply updated the xcode project and podfile to look for stuff at
../../../node_modules
instead of../node_modules
, and then I duplicated the.command
file that gets opened in a new window and added a step to CD into thepackages/mobile-professional
folder (otherwise it runs in the wrong directory and metro doesn't pick up the config that I've got inside that folder).For the android stuff, I first adjusted the build.grade, app/build.gradle and settings.graddle to look up 2 directories more than before, which gets me farther but then i get
A problem occurred evaluating settings ... Text must not be null or empty
. I've tried various react-native.config.js values in both the root and my folder (and pointing the android dir within both to./android
and./packages/mobile-professional/android
) but that does not work with the old cli or the new. If I modify the native_modules.gradle file that gets installed as part of cli, (or the android subcomponent), so that it runsreact-native config
in the mobile folder rather than the root, I finds what it wants, but then I get some build errors about not being able to findandroid.support.annotations.nullable
in one of the native components, saying more specifically thatandroid.support.annotations
doesn't exist, which feels like a linking issue.Just to make sure it's not a hangup, re: react-native.config.js, i've also moved the limited rnpm stuff (just assets) in there as well out of the package.json
I'm trying to set up an example repo, as ours is closed and stripping things out has proven time consuming (we have a lot of process going on, everything is built in reasonml and compiled with bucklescript down to JS). In the meantime I'm posting original versions of my build and config files, and new versions.
app-build.gradle-modified.txt
app-build.gradle-original.txt
build.gradle-modified.txt
build.gradle-original.txt
metro.config.js.txt
mobile-professional-package.json.txt
rn-cli.config.js.txt
settings.gradle-modified.txt
settings.gradle-original.txt
Sorry again for the huge wall of text, but I figured it was better to provide everything relevant rather than too little.
The text was updated successfully, but these errors were encountered: