Home > other >  Can I use the same codebase for both a React Native macOS app and a React Native Windows app?
Can I use the same codebase for both a React Native macOS app and a React Native Windows app?

Time:10-19

I am trying to create an app using React Native that runs on iOS, Android, macOS and Windows. An advantage of being able to use React Native is that you can share code between platforms.

I am following the setup guides for React Native macOS and Windows, but in the guides, they guide you through creating a new app from scratch for each platform. As I want to use the same app, so I don't have to write the same code twice, I create the macOS app following the guide. Then, in this app, I use the command npx react-native-windows-init --overwrite from the Windows guide to initialise the Windows platform. But when I then go to run the macOS app using the command npx react-native run-macos, I get the error:

Cannot find module 'metro-config/src/defaults/exclusionList'

and

no bundle URL present

One thing I find strange about the setup guides is that for macOS it tells you to use React Native 0.63 and for Windows 0.66. I used 0.66 for both, maybe this is the problem. But if it is, and each platform requires different versions of React Native, how can I use the one app / codebase for both platforms? This goes against one of React Native's core premises:

Create platform-specific versions of components so a single codebase can share code across platforms.

Is it possible to create a single app for both desktop platforms like you would with iOS and Android, and if so, how?


CodePudding user response:

Yes, you can. You will have to create a mono repo Or you can use mono repo boilerplate. Here is a link to it https://github.com/mmazzarolo/react-native-universal-monorepo

  • Related