react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Unable to debug new Hermes React Native app using Chrome DevTools

Open DigitalZebra opened this issue 2 years ago • 12 comments
trafficstars

Description

I'm unable to debug a new React Native app that's using Hermes by following the Hermes debugging instructions found here: https://reactnative.dev/docs/hermes#debugging-js-on-hermes-using-google-chromes-devtools

Upon following those steps and opening the console in the stand alone Chrome DevTools, I see this error:

DevTools failed to load source map: Could not load content for http://localhost:8081/index.map?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.tempRN0710RC3: Fetch through target failed: Cannot read properties of null (reading 'loadNetworkResource'); Fallback: Unknown error

Nothing shows up in the Sources tab. Navigating to that URL outside of the dev tools does load the source map file successfully.

I am able to debug successfully using Flipper - source maps seem to load fine there.

Version

0.71.0-rc.3

Output of npx react-native info

info Fetching system and libraries information...
System:
    OS: macOS 12.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 2.67 GB / 32.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.0 - ~/.nvm/versions/node/v16.13.0/bin/node
    Yarn: 1.22.17 - ~/.nvm/versions/node/v16.13.0/bin/yarn
    npm: 8.1.0 - ~/.nvm/versions/node/v16.13.0/bin/npm
    Watchman: 2022.03.21.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 14.1/14B47b - /usr/bin/xcodebuild
  Languages:
    Java: 18.0.1.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.0-rc.3 => 0.71.0-rc.3 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

  1. Create a new React Native project using the command: npx react-native init RN0710RC3 --version 0.71.0-rc.3
  2. Once created, cd in to project directory. Run using yarn ios or yarn android
  3. Follow steps outlined in Hermes debugging documentation: https://reactnative.dev/docs/hermes#debugging-js-on-hermes-using-google-chromes-devtools
  4. Notice source maps don't load, unable to set breakpoints.

Snack, code example, screenshot, or link to a repository

No code example since it's reproducible using a new RN 70 or 71 project: npx react-native init RN0710RC3 --version 0.71.0-rc.3

image

DigitalZebra avatar Dec 09 '22 01:12 DigitalZebra

Recent versions of Chrome have stopped fetching sources from URLs in this scenario. We have an upcoming fix that will restore this functionality (by fetching the source directly, instead of via a URL). In the meantime, the easiest way to restore source loading is by using a previous version of Chrome, or Flipper.

mattbfb avatar Dec 09 '22 13:12 mattbfb

Hi, same issues

System: OS: macOS 12.6 CPU: (8) arm64 Apple M1 Memory: 116.91 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.17.0 - /usr/local/bin/node Yarn: 1.22.19 - /opt/homebrew/bin/yarn npm: 8.15.0 - /usr/local/bin/npm Watchman: 2022.09.26.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /Users/danil/.rvm/gems/ruby-2.7.5/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9014738 Xcode: 14.0/14A309 - /usr/bin/xcodebuild Languages: Java: 11.0.16.1 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.6 => 0.70.6 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

image

Kasik-D avatar Dec 16 '22 11:12 Kasik-D

Thanks @mattbfb - would you recommend I close this or leave it open for tracking purposes? Thanks again for the background - I'll use Flipper for the time being.

DigitalZebra avatar Dec 26 '22 18:12 DigitalZebra

Recent versions of Chrome have stopped fetching sources from URLs in this scenario. We have an upcoming fix that will restore this functionality (by fetching the source directly, instead of via a URL). In the meantime, the easiest way to restore source loading is by using a previous version of Chrome, or Flipper.

We can't use flipper in our case as it's not compatible with react-native-firebase. So this issue is quite a show-stopper for our react-native upgrade initiative.

Any suggestions over how source map could be added manually? Thanks.

hishammalik avatar Dec 30 '22 00:12 hishammalik

It seems like this should have been fixed in the latest 0.71 release.

By loading source maps over the network with Metro we’ve restored the ability to use source maps in recent versions of Chrome Dev Tools outside of Flipper.

https://reactnative.dev/blog/2023/01/12/version-071#hermes

However, I'm still not able to load source maps with the same error as above: DevTools failed to load source map: Could not load content for http://localhost:8081/index.map?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=appname: Fetch through target failed: Cannot read properties of null (reading 'loadNetworkResource'); Fallback: Unknown error

Any ideas on how to get around this or if it's still an outstanding issue? Thanks!

System:
    OS: macOS 13.1
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
    Memory: 27.85 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 19.1.0 - /usr/local/bin/node
    Yarn: 1.22.19 - ~/project-name/node_modules/.bin/yarn
    npm: 8.19.3 - /usr/local/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.3 - /Users/bbrook/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 14.1/14B47b - /usr/bin/xcodebuild
  Languages:
    Java: 16.0.1 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.1 => 0.71.1 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

benrbrook avatar Jan 20 '23 05:01 benrbrook

I'm still seeing this issue with react native v0.71.1 and Chrome 109.0.5414.119

wadeww avatar Jan 25 '23 16:01 wadeww

I'm also seeing the same issue as @benrbrook with react native v0.71.1 and Chrome 109.0.5414.119

robincwillis avatar Jan 28 '23 22:01 robincwillis

I'm seeing a similar issue with react-native-debugger and RN v0.71

bcsaxon avatar Feb 06 '23 23:02 bcsaxon

same issue. devtools didnt work https://reactnative.dev/docs/hermes#debugging-js-on-hermes-using-google-chromes-devtools

itsmeshusha avatar Feb 07 '23 15:02 itsmeshusha

Just thought I'd add my two cents. This is also happening for me on 0.71.2 and Chrome Version 110.0.5481.77. Console doesn't show logs and files don't show up in Sources. Actually, they've never showed up in Sources, but I could definitely use the Console before. Also using react-native-firebase so cannot use Flipper. Hoping for some guidance soon, thank you!

gabriellend avatar Feb 15 '23 22:02 gabriellend

I also cannot get this to work with react-native-debugger and RN v0.71. Any update?

jaexplorer avatar Feb 22 '23 20:02 jaexplorer

It seems source maps are disabled by default. Could that be related?

matthewmturner avatar Mar 07 '23 22:03 matthewmturner

@matthewmturner I was able to get the debugger to work when following those instructions, but only when running from XCode. We are also using Firebase.

dnelsonlivecurrence avatar Mar 14 '23 12:03 dnelsonlivecurrence

any updates ?

pratt3351 avatar Mar 15 '23 06:03 pratt3351

image a temporary workaround is to disable the js source maps option in the devtool 😵‍💫

nguyenthetoan avatar Mar 17 '23 03:03 nguyenthetoan

This seems to be still happening on 0.71.4. Has anyone able to find a workaround?

yusufseyrek avatar Mar 29 '23 00:03 yusufseyrek

I had to temporarily disable Hermes in Podfile :hermes_enabled => false, for debug mode to be able to use react-native-debugger. Any other workarounds?

hpelitebook745G2 avatar Apr 02 '23 16:04 hpelitebook745G2

Do you need to also disable hermes in Android for it to work? If so, how do you disable hermes in Android?

jaexplorer avatar Apr 02 '23 23:04 jaexplorer

Android seems fine and I can use still react-native-debugger without disabling Hermes so I only do it in iOS. But to answer your question, I'm using the latest RN 0.71.4 so it should be in android/app/build.gradle and invert the flag hermesEnabled:

    if (hermesEnabled.toBoolean()) {
        implementation("com.facebook.react:hermes-android")
    } else {
        implementation jscFlavor
    }

hpelitebook745G2 avatar Apr 03 '23 18:04 hpelitebook745G2

The state of debugging RN has been a difficult one from the beginning. Most developers use console.log to "debug" to this day. There is no integration into VScode (which has an excellent debugger) and hermes does not improve a lot in that regard. I wonder if there are any devs out there who managed to get debugging working (consistently)?

pke avatar Apr 27 '23 10:04 pke

Still have this problem. It seems that I should use use older version of react native.

willTerner avatar May 13 '23 14:05 willTerner

anyone knows if this is getting adressed in v0.72 ? On Android I can debug with Hermes enabled, and it is actually a lot better in terms of performance debugging Android with Hermes, we just need to be able to debug on ios (we cant use flipper on our project)

Lakston avatar Jun 07 '23 06:06 Lakston

Having the same issue in react-native:0.71.8, getting this error: Calling synchronous methods on native modules is not supported in Chrome.

surbhidavara99 avatar Jun 12 '23 10:06 surbhidavara99

I had to temporarily disable Hermes in Podfile :hermes_enabled => false, for debug mode to be able to use react-native-debugger. Any other workarounds?

I am using RN 0.70.10 and cannot have both hermes disabled and flipper disabled as I get a build errors related to hermes.h or Thread 1: signal SIGABRT because of "Library not loaded: @rpath/hermes.framework/hermes".

Edit: Solved this crash by doing as suggested here, but debugging still doesn't work. Still getting error even with hermes on false and flipper disabled: info Opening flipper://null/Hermesdebuggerrn?device=React%20Native... error Browser exited with error:, Error: invalid url, missing http/https protocol

Did you do any other command apart from the disabling of hermes and pod install again? I also see that my project's /* [CP] Embed Pods Frameworks */ task is being deleted from the project.pbxproj after disabling hermes, is this normal?

I am also using react-native-firebase, so I cannot use Flipper. This is making it impossible to debug the iOS app on Mac. :(

R4DIC4L avatar Jun 29 '23 14:06 R4DIC4L

Still seeing this as of react-native:0.71.12 on IOS.

Tried generating a bundle with a sourcemap by adding the sourcemap-output flag to my build command (see below) and adding export SOURCEMAP_FILE="$(pwd)/../main.jsbundle.map"; to my ios/.xcode.env file as stated here. With this I do see a sourcemap file created but somehow it is not being picked up by the chrome debugger.

The whole build command I used is this react-native bundle --entry-file='index.js' --bundle-output='./ios/main.jsbundle' --dev=true --platform='ios' --sourcemap-output='./ios/main.jsbundle.map'

mandrade2 avatar Jul 11 '23 22:07 mandrade2

I'm experiencing the same issue with react-native:0.71.12 on IOS. Subscribing...

Barrakkuda avatar Jul 22 '23 05:07 Barrakkuda

:warning: Missing Reproducible Example
:information_source: We could not detect a reproducible example in your issue report. Please provide either:
  • If your bug is UI related: a Snack
  • If your bug is build/update related: use our Reproducer Template. A reproducer needs to be in a GitHub repository under your username.

github-actions[bot] avatar Jul 22 '23 05:07 github-actions[bot]

temporary solution

in android/app/build.gradle file

in dependencies reverse if else case for hermesEnabled.toBoolean()

saurabhsaneja avatar Sep 11 '23 11:09 saurabhsaneja

This works for me: https://github.com/gusgard/react-native-devsettings

jkoutavas avatar Oct 27 '23 15:10 jkoutavas

[@jkoutavas]) thanks.. I will try

app://arkansasSaneja

saurabhsaneja avatar Oct 27 '23 17:10 saurabhsaneja