question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to run react-native app in Debug mode from Xcode

See original GitHub issue

Current 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:open
  • Created a year ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
curthipstercommented, Sep 21, 2022

I just tested with 14.7.6, which includes https://github.com/nrwl/nx/pull/11971. I was able to build and run in XCode.

Edit: it worked at first, and now it’s not. I can’t tell what’s changed. Argh.

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

0reactions
chrismcleodcommented, Oct 19, 2022

I think this happens bc of this image

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

cd "$(dirname "$0")" && yarn nx start "MyCoolApp"

Update the Xcode launch script: open "$SRCROOT/../launch.command" || echo "Can't start packager automatically"

Probably not the best long-term solution.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't debug react-native project from Xcode, but It's running ...
When I'm running react-native run-iso it runs emulator, and everything is perfect. However, if I'll go into ios directory and try to build...
Read more >
Unable to run app from Xcode on iP… - Apple Developer
I am unable to run my app from Xcode on iPhone without disabling debug in Scheme (or selecting "Ask on Launch" for Executable)....
Read more >
Debugging - React Native
Accessing the In-App Developer Menu. ... You can then select "Debug JS Remotely" from the Developer Menu to start debugging.
Read more >
Debugging common React Native issues on iOS - Pusher Blog
Most of the time, what causes your build to fail is that you have an outdated version of Xcode. To update Xcode, open...
Read more >
Debugging - Expo Documentation
You can debug React Native apps using the Chrome debugger tools. Rather than running your app's JavaScript on your phone, it will instead...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found