facebook / react-native

A framework for building native applications using React
https://reactnative.dev
MIT License
119.56k stars 24.37k forks source link

Unable to debug new Hermes React Native app using Chrome DevTools #35600

Closed DigitalZebra closed 4 months ago

DigitalZebra commented 1 year ago

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
mattbfb commented 1 year ago

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.

Kasik-D commented 1 year ago

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

DigitalZebra commented 1 year ago

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.

hishammalik commented 1 year ago

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.

benrbrook commented 1 year ago

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
wadeww commented 1 year ago

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

robincwillis commented 1 year ago

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

bcsaxon commented 1 year ago

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

itsmeshusha commented 1 year ago

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

gabriellend commented 1 year ago

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!

jaexplorer commented 1 year ago

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

matthewmturner commented 1 year ago

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

dnelsonlivecurrence commented 1 year ago

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

pratt3351 commented 1 year ago

any updates ?

nguyenthetoan commented 1 year ago

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

yusufseyrek commented 1 year ago

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

hpelitebook745G2 commented 1 year ago

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?

jaexplorer commented 1 year ago

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

hpelitebook745G2 commented 1 year ago

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
    }
pke commented 1 year ago

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)?

willTerner commented 1 year ago

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

Lakston commented 1 year ago

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)

surbhidavara99 commented 1 year ago

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

R4DIC4L commented 1 year ago

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

mandrade2 commented 1 year ago

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'

Barrakkuda commented 1 year ago

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

github-actions[bot] commented 1 year ago
: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.
saurabhsaneja commented 1 year ago

temporary solution

in android/app/build.gradle file

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

jkoutavas commented 1 year ago

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

saurabhsaneja commented 1 year ago

[@jkoutavas]) thanks.. I will try

app://arkansasSaneja

HoangTrongKhanh commented 1 year ago

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

Sorry, Im using MKKV so this library didnt work for me

HoangTrongKhanh commented 1 year ago

Any updates?

jkoutavas commented 1 year ago

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

Sorry, Im using MKKV so this library didnt work for me

Do you mean this? https://github.com/mrousavy/react-native-mmkv

If so, why doesn't it work?

antoniovuono commented 1 year ago

Same issue here in React Native: 0.71.11

CrazyStoneJy commented 1 year ago

same issue in 0.72.6

ou2s commented 1 year ago

Same issue with 0.72.7... Unable to have breakpoint working on Flipper with a new project on iOS.

JsonKit commented 11 months ago

@jkoutavas Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.

Hao-yiwen commented 10 months ago

I have a little same question.I found my breakpoints will not work when I press "R" to refresh my page.

react-native-bot commented 4 months ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

react-native-bot commented 4 months ago

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

react-native-bot commented 4 months ago

This issue was closed because it has been stalled for 7 days with no activity.

markalanevans commented 3 months ago

Same issue.

linkecoding commented 1 month ago

I think I found a temporary solution by using a lower version of the Chrome browser for debugging. After my test, the browser version 80.0.3987.149 can be debugged. You can download it at this link,google-chrome-old-version

linkecoding commented 1 month ago

I am currently using React Native 0.73.4, Android device, I tried several ways, and finally found the following differences

  1. If I set the value of [Debug server host & port for device] to my computer's [ip ​​address: 8081] through the debug panel's [Settings], an error [Failed to fetch source url http://192.168.31.228:8081/index.bundle//&platform=android&dev=true&lazy=true&minify=false&app=com.reactnativesample&modulesOnly=false&runModule=true: remote fetches not permitted] will appear
  2. If I set it to [localhost:8081] in the same way, and use USB to connect the device, and execute the command [adb reverse tcp:8081 tcp:8081], my latest version of Chrome can load source map files and debug normally code, the above error will not occur
  3. If I set it to [127.0.0.1:8081], a loading error will also occur So the current appropriate solution is to set the value of [Debug server host & port for device] to localhost:8081 and execute [adb reverse tcp:8081 tcp:8081]
linkecoding commented 1 month ago

For users who use the iOS simulator, the feasible method is:

  1. Get the IP address of your PC, assuming it is 192.168.31.3
  2. Edit the file [/etc/hosts], which requires sudo permissions, and add a line to this file:

localhost 192.168.31.3

In this way, your simulator can still use localhost to pull RN's js files, but it will be pointed to the local server of your computer.