Skip to content
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

[expo-51] Android app unable to resolve module expo-router/entry inside monorepo (new arch enabled or not) #28775

Open
sync opened this issue May 12, 2024 · 2 comments
Assignees
Labels
needs review Issue is ready to be reviewed by a maintainer pending closure awaiting final response before closing

Comments

@sync
Copy link
Contributor

sync commented May 12, 2024

Minimal reproducible example

https://github.com/sync/borg

What platform(s) does this occur on?

Android

Did you reproduce this issue in a development build?

Yes

Summary

When I run the app on Android in development mode I get the following error as soon as I add to the metro config monorepo support as per your documentation. The same app if not run inside a monotrepo work just fine. And the exact same config on iOS is fine.

/Users/xxx/Projects/expo/borg-mono/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:112
        throw new UnableToResolveError(
              ^
Error: Unable to resolve module ./node_modules/expo-router/entry from /Users/xxx/Projects/expo/borg-mono/apps/borg/.: 

None of these files exist:
  * node_modules/expo-router/entry(.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.mjs|.native.mjs|.mjs|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.scss|.native.scss|.scss|.android.sass|.native.sass|.sass|.android.css|.native.css|.css)
  * node_modules/expo-router/entry/index(.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.mjs|.native.mjs|.mjs|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.scss|.native.scss|.scss|.android.sass|.native.sass|.sass|.android.css|.native.css|.css)
    at ModuleResolver.resolveDependency (/Users/xxx/Projects/expo/borg-mono/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:112:15)
    at DependencyGraph.resolveDependency (/Users/xxx/Projects/expo/borg-mono/node_modules/metro/src/node-haste/DependencyGraph.js:231:43)
    at /Users/xxx/Projects/expo/borg-mono/node_modules/metro/src/lib/transformHelpers.js:156:21
    at HmrServer._registerEntryPoint (/Users/xxx/Projects/expo/borg-mono/node_modules/metro/src/HmrServer.js:49:35)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Promise.all (index 0)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed.
Exit code: 1
Command: /Users/xxx/Library/Application Support/fnm/node-versions/v18.19.1/installation/bin/node
Arguments: /Users/xxx/Library/Application Support/fnm/node-versions/v18.19.1/installation/lib/node_modules/yarn/lib/cli.js android
Directory: /Users/xxx/Projects/expo/borg-mono/apps/borg
Output:
Screenshot 2024-05-12 at 4 53 13 PM

iOS

works perfectly

Environment

expo-env-info 1.2.0 environment info:
System:
OS: macOS 14.4.1
Shell: 5.9 - /bin/zsh
Binaries:
Node: 18.19.1 - ~/Library/Caches/fnm_multishells/6402_1715493990830/bin/node
Yarn: 1.22.22 - ~/Library/Caches/fnm_multishells/6402_1715493990830/bin/yarn
npm: 10.2.4 - ~/Library/Caches/fnm_multishells/6402_1715493990830/bin/npm
Watchman: 2024.05.06.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.15.2 - /Users/anthonymittaz/.gem/ruby/2.7.4/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 23.4, iOS 17.4, macOS 14.4, tvOS 17.4, visionOS 1.1, watchOS 10.4
IDEs:
Android Studio: 2023.2 AI-232.10300.40.2321.11567975
Xcode: 15.3/15E204a - /usr/bin/xcodebuild
npmGlobalPackages:
eas-cli: 9.0.2
Expo Workflow: bare

Expo Doctor Diagnostics

✔ Check Expo config for common issues
✔ Check package.json for common issues
✔ Check dependencies for packages that should not be installed directly
✔ Check for issues with metro config
✔ Check for common project setup issues
✔ Check npm/ yarn versions
✔ Check Expo config (app.json/ app.config.js) schema
✔ Check native tooling versions
✔ Check for legacy global CLI installed locally
✔ Check that native modules do not use incompatible support packages
✔ Check that packages match versions required by installed Expo SDK
✔ Check that native modules use compatible support package versions for installed Expo SDK

Didn't find any issues with the project!
@sync sync added the needs validation Issue needs to be validated label May 12, 2024
@expo-bot expo-bot added needs review Issue is ready to be reviewed by a maintainer and removed needs validation Issue needs to be validated labels May 12, 2024
@sync sync changed the title [expo-51] Android build unable to resolve module expo-router/entry inside monorepo (new arch enabled or not) [expo-51] Android app unable to resolve module expo-router/entry inside monorepo (new arch enabled or not) May 12, 2024
@sync
Copy link
Contributor Author

sync commented May 12, 2024

EXPO_USE_METRO_WORKSPACE_ROOT=1 in a .env or before the start command fixes it, I guess it is required ?

@byCedric
Copy link
Member

Hi @sync! Thanks for reporting this issue. Monorepos are hard, and the resolving logic in Metro isn't helping here at all. Eventhough I can't seem to reproduce this exact issue in your repository, one way this might be fixed (besides the EXPO_USE_METRO_WORKSPACE_ROOT=1) is this:

  • Create your own entryfile, e.g. apps/borg/index.ts
  • Only add import 'expo-router/entry'; in this entry file
  • Change apps/borg/package.json main to index.ts.

This is because Metro might not play nice with a combination of entry points from node_modules and monorepos. I do the exact same thing in my monorepo example here.

Hope this helps!

@byCedric byCedric self-assigned this May 12, 2024
@byCedric byCedric added the pending closure awaiting final response before closing label May 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs review Issue is ready to be reviewed by a maintainer pending closure awaiting final response before closing
Projects
None yet
Development

No branches or pull requests

3 participants