Unable to run react-native app in Debug mode from Xcode
See original GitHub issueCurrent Behavior
When triggering a react-native app from within Xcode in Debug build configuration I get the error:
Error: Unable to resolve module ./src/main from /Users/nathanjulianomeibergen/Documents/development/happynrwl/.
Expected Behavior
I’d expect the app simply to start successfully.
I believe however that this did used to work. I recently migrated to the latest NX version - 14.7.5 -, but I am not 100% sure that it used to. My approach is mostly to run the Release version in Xcode for Archiving purposes.
Why I want this?
In my real-world application I stumble upon an error when running nx run-ios myapp
. For better debugging purposes the error even suggest to try running from Xcode. The Release version starts up fine, that’s why I wanted to know what is happening in Debug mode.
Steps to Reproduce
In order to reproduce simply run (as described here):
npx create-nx-workspace happynrwl \
--preset=react-native \
--appName=mobile
Now head to apps/mobile/ios/
and open Mobile.xcworkspace
. Then in Xcode ‘Edit Scheme’ and make sure that the ‘Build Configuration’ is set to ‘Debug’.
Environment
Info from npx react-native info
:
System:
OS: macOS 12.6
CPU: (8) arm64 Apple M1
Memory: 201.17 MB / 16.00 GB
Shell: 5.8.1 - /bin/zsh
Binaries:
Node: 18.9.0 - /opt/homebrew/bin/node
Yarn: 1.22.19 - /opt/homebrew/bin/yarn
npm: 8.19.1 - /opt/homebrew/bin/npm
Watchman: 2022.09.05.00 - /opt/homebrew/bin/watchman
Managers:
CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK: Not Found
IDEs:
Android Studio: Not Found
Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
Languages:
Java: 11.0.10 - /usr/bin/javac
npmPackages:
@react-native-community/cli: 9.0.0 => 9.0.0
react: 18.2.0 => 18.2.0
react-native: 0.69.4 => 0.69.4
react-native-macos: Not Found
npmGlobalPackages:
*react-native*: Not Found
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top GitHub Comments
I figured out what the difference is. If metro is already running when launching the app from within XCode, then it runs. If XCode launches metro, then it results in
Error: Unable to resolve module ./src/main...
I think this happens bc of this
if you echo $THIS_PATH in launchPackager.command, it’s the root of the monorepo, not the apps/appName directory. This is probably bc of the symlinked node_modules folder.
I added/used a custom launch command file in the root of the app folder and it works.
apps/MyCoolApp/launch.command
Update the Xcode launch script:
open "$SRCROOT/../launch.command" || echo "Can't start packager automatically"
Probably not the best long-term solution.