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

Unable to resolve module ./node_modules/expo-router/entry in monorepo #748

Closed
hyoretsu opened this issue Jul 7, 2023 · 9 comments
Closed

Comments

@hyoretsu
Copy link

hyoretsu commented Jul 7, 2023

Which package manager are you using? (Yarn is recommended)

pnpm (known issues due to Metro)

Summary

I can't start an app with Expo Router v2, Expo 49 and PNPM. I already tried expo-router/entry and manually specifying the node_modules path to both local and workspace. I also already tried with and without the .npmrc settings.

Error: Unable to resolve module ./node_modules/expo-router/entry from /home/hyoretsu/@Projects/numerical-analysis/mobile/.: 

None of these files exist:
  * node_modules/expo-router/entry(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.svg|.native.svg|.svg)
  * node_modules/expo-router/entry/index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.cjs|.native.cjs|.cjs|.android.svg|.native.svg|.svg)
    at ModuleResolver.resolveDependency (/home/hyoretsu/@Projects/numerical-analysis/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:114:15)
    at DependencyGraph.resolveDependency (/home/hyoretsu/@Projects/numerical-analysis/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
    at /home/hyoretsu/@Projects/numerical-analysis/node_modules/metro/src/lib/transformHelpers.js:169:21
    at Server._resolveRelativePath (/home/hyoretsu/@Projects/numerical-analysis/node_modules/metro/src/Server.js:1045:12)
    at async Server.requestProcessor [as _processBundleRequest] (/home/hyoretsu/@Projects/numerical-analysis/node_modules/metro/src/Server.js:449:37)
    at async Server._processRequest (/home/hyoretsu/@Projects/numerical-analysis/node_modules/metro/src/Server.js:383:7)

Minimal reproducible example

numerical-analysis.zip

@hyoretsu
Copy link
Author

hyoretsu commented Jul 7, 2023

This also happens with yarn, even though it clearly exists
image

@hyoretsu hyoretsu changed the title Unable to resolve module Unable to resolve module ./node_modules/expo-router/entry in monorepo Jul 7, 2023
@hyoretsu
Copy link
Author

hyoretsu commented Jul 7, 2023

Tracked it down, it's an issue with monorepos, at least PNPM's. I can run it just fine in an isolated project.

@EvanBacon
Copy link
Contributor

Create an index.js file and add:

import "expo-router/entry"

Then remove the main field in the project package.json

@hyoretsu
Copy link
Author

hyoretsu commented Jul 7, 2023

Thank you. That should be noted in the docs somewhere though, RN monorepo's already hard as it is.

@nathan-charles
Copy link

Create an index.js file and add:

import "expo-router/entry"

Then remove the main field in the project package.json

i'm still getting the below error only when building in release mode even after verifying the above.

❌ Metro encountered an error:
The resource .../react-native-app/index.js was not found.

@marklawlor
Copy link
Contributor

@nathan-charles Its hard for us to assist you with a filepath issue when we cannot see your repo. Can you please create a new issue with a reproduction repo so we can assit you.

@nathan-charles
Copy link

@marklawlor Thanks for the reply I was finally was able to resolve my issue first I had to remove the EXPO_USE_METRO_WORKSPACE_ROOT=1 env variable as instructed in mono repo guide I'm not sure what this is for or if it's even necessary but it does not work with expo-router when building a release app also another issue was due to react-native-reanimated dependency I was running 3.3.0 as recommend by expo doctor but after upgrading to 3.5.2 I was finally able to create release build.

See the release notes here:
https://github.com/software-mansion/react-native-reanimated/releases/tag/3.5.2

@Chibuife
Copy link

tried the

Create an index.js file and add:

import "expo-router/entry"

Then remove the main field in the project package.json

I tried the same thing but got this error instead.

react-dom.development.js:18687 The above error occurred in the <withDevTools(Anonymous)> component:

at withDevTools(Anonymous)

Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

@waymond91
Copy link

waymond91 commented Nov 24, 2023

I just created a fresh app:

npx create-expo-app VoiceTestApp2

Installed the modules with yarn & tested again with npm.

Doing npx expo run:anroid or npx expo start gives the following:

› Opening exp+voicetestapp2://expo-development-client/?url=http%3A%2F%2F192.168.0.101%3A8081 on SM_A528B

› Logs for your project will appear below. Press Ctrl+C to exit.
Error: Unable to resolve module ./.expo/.virtual-metro-entry from /Users/brett/.:

None of these files exist:
  * ../.expo/.virtual-metro-entry(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
  * ../.expo/.virtual-metro-entry/index(.native|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx|.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json)
    at ModuleResolver.resolveDependency (/Users/brett/VoiceTestApp2/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:114:15)
    at DependencyGraph.resolveDependency (/Users/brett/VoiceTestApp2/node_modules/metro/src/node-haste/DependencyGraph.js:277:43)
    at /Users/brett/VoiceTestApp2/node_modules/metro/src/lib/transformHelpers.js:169:21
    at Server._resolveRelativePath (/Users/brett/VoiceTestApp2/node_modules/metro/src/Server.js:1045:12)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Server.requestProcessor [as _processBundleRequest] (/Users/brett/VoiceTestApp2/node_modules/metro/src/Server.js:449:37)
    at async Server._processRequest (/Users/brett/VoiceTestApp2/node_modules/metro/src/Server.js:383:7)
› Stopped server

package.json:

➜  VoiceTestApp2 git:(main) ✗ cat package.json
{
  "name": "voicetestapp2",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo run:android",
    "ios": "expo run:ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~49.0.15",
    "expo-modules-core": "~1.5.12",
    "expo-splash-screen": "~0.20.5",
    "expo-status-bar": "~1.6.0",
    "react": "18.2.0",
    "react-native": "0.72.6"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

app.json:

{
  "expo": {
    "name": "VoiceTestApp2",
    "slug": "VoiceTestApp2",
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "userInterfaceStyle": "light",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    },
    "android": {
      "adaptiveIcon": {
        "foregroundImage": "./assets/adaptive-icon.png",
        "backgroundColor": "#ffffff"
      },
      "package": "com.brettmsmith.VoiceTestApp2"
    },
    "web": {
      "favicon": "./assets/favicon.png"
    }
  }
}
➜  VoiceTestApp2 git:(main) ✗ npx expo start -c
Starting project at /Users/brett/VoiceTestApp2
Error: Cannot find module 'expo/metro-config'
Require stack:
- /Users/brett/metro.config.js
- /Users/brett/VoiceTestApp2/node_modules/import-fresh/index.js
- /Users/brett/VoiceTestApp2/node_modules/cosmiconfig/dist/loaders.js
- /Users/brett/VoiceTestApp2/node_modules/cosmiconfig/dist/createExplorer.js
- /Users/brett/VoiceTestApp2/node_modules/cosmiconfig/dist/index.js
- /Users/brett/VoiceTestApp2/node_modules/metro-config/src/loadConfig.js
- /Users/brett/VoiceTestApp2/node_modules/metro-config/src/index.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/metro-config/build/traveling/metro-config.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/metro-config/build/ExpoMetroConfig.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/start/server/metro/resolveFromProject.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/utils/analytics/getMetroProperties.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/start/server/metro/instantiateMetro.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/start/server/metro/MetroBundlerDevServer.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/start/server/DevServerManager.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/start/startAsync.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/src/start/index.js
- /Users/brett/VoiceTestApp2/node_modules/@expo/cli/build/bin/cli
- /Users/brett/VoiceTestApp2/node_modules/expo/bin/cli

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants