expo-monorepo-example icon indicating copy to clipboard operation
expo-monorepo-example copied to clipboard

Trouble getting "expo-router" installed + starting

Open owenduncansnobel opened this issue 1 year ago • 3 comments

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.

owenduncansnobel avatar Jul 02 '23 21:07 owenduncansnobel

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;
  1. Instead of using "main": "expo-router/entry" in "package.json", creating an "index.js" file and using that as the main entry.
  2. 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).

tichopad avatar Jul 11 '23 21:07 tichopad

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!

owenduncansnobel avatar Jul 11 '23 21:07 owenduncansnobel

@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.

tichopad avatar Jul 15 '23 13:07 tichopad

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!

byCedric avatar May 09 '24 12:05 byCedric