Search code examples
androidiosreact-nativeexpomonorepo

"Unable to resolve module ./src/main" when building a react-native app from an NX monorepo after installing Expo


What I'have done

  • Created a NX monorepo with the react-native preset
  • yarn add expo from workspace directory
  • added metro dependency manually to package.json in the react native app directory
  • pod install in the ios directory of the react native app
  • edit of some files manually accordingly to the Expo manual setup guide (https://docs.expo.dev/bare/installing-expo-modules/)

The only thing that I did different from the original Expo guide is that I edited this line

   UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"main" initialProperties:nil]; 

in

UIView *rootView = [self.reactDelegate createRootViewWithBridge:bridge moduleName:@"myappname" initialProperties:nil];

Now, the app build fine but metro gives me this error:

Error: Unable to resolve module ./src/main from /Users/myusername/Documents/GitHub/folder/monorepo/

And that's correct because this is the path to the nx workspace not the react native app directory! Before setting up expo it worked well so I guess expo here is the problem. Do you have any idea of how correct this? It looks that nx and expo are not working very well together.


Solution

  • You can amend the path in AppDelegate.mm (or AppDelegate.m file. as i know the extension name dependes on react-native version).

    enter image description here

    jsBundleURLForBundleRoot point out the wrong path @"src/main" as you see in the image

    after i edit the path from src/main to apps/rn-pjt-name/src/main.ts, error disappear

    reference: https://github.com/nrwl/nx-react-native/issues/40#issuecomment-979193844