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
720 stars 76 forks source link

Trouble getting "expo-router" installed + starting #97

Closed owenduncansnobel closed 5 months ago

owenduncansnobel commented 1 year ago

Description of the bug

Is there an example of getting "expo-router" working with this repo? I have been trying to add it but I am getting errors when trying to install it.

tichopad commented 1 year ago

Hey @owen-duncan-snobel I went down this rabbit hole as well.

I've finally been able to somewhat figure it out by:

  1. Deleting the following setting from "metro.config.js":
    // #3 - Force resolving nested modules to the folders below
    config.resolver.disableHierarchicalLookup = true;
  2. Instead of using "main": "expo-router/entry" in "package.json", creating an "index.js" file and using that as the main entry.
  3. Adding import "expo-router/entry" to the "index.js".

The main issue I've been having is Metro not being able to resolve "expo-router/entry". I guess the resolution process is different for imports and the "main" field in package.json. It also doesn't seem to work with hierarchical lookup disabled.

I can provide you with an example project setup later if you want. Btw I'm using the official tabs template for my app workspace and I'm also using pnpm with hoisted node-linker (as this repo does).

owenduncansnobel commented 1 year ago

I can provide you with an example project setup later if you want. Btw I'm using the official tabs template for my app workspace and I'm also using pnpm with hoisted node-linker (as this repo does).

Ya if you were able to post an example of the setup later that would be amazing!

tichopad commented 1 year ago

@owen-duncan-snobel Sorry it took so long. I got distracted by Diablo 4 lol.

Here you go https://github.com/tichopad/expo-monorepo-example/tree/main/apps/mobile-with-router.

It should work out of the box. Although I haven't tested EAS Build.

byCedric commented 5 months ago

Sorry it took a while! Next time, do ping me on Twitter @cedric_dev.

Yep, @tichopad is right, disableHierarchicalLookup shouldn't be disabled anymore. This used to be required due to various issues in both the native layers of React Native, as well as Metro. These have now all been fixed, and our docs has been updated to mention this too:

image

I also updated this monorepo to use Expo SDK 51, and removed this property. Hope this helps!