0

I am trying to understand and debug existing react-native code for mobile app. I am using Visual Studio as editor. I am building the app in mobile and not using simulator for building the app. I am using console.log() statements for logging the values/responses. After/During I build the app, I do not see any log printed in the terminal. How do I print the console statement in VS code for react-native app?

Thank you in advance.

Neha
  • 95
  • 1
  • 12

2 Answers2

0

You're probably looking for this

The setup is different for iOS and android, but this will allow you to connect to the chrome dev tools via USB and see the console.log statements in the browser console.

On iOS:

Find and edit RCTWebSocketExecutor.m, change the value of "localhost" to your computers IP address

and android:

run adb reverse tcp:8081 tcp:8081

Then you can open the dev menu on your app (by shaking your phone) and select "Debug JS remotely"

Alternatively, you can use console.warn instead of console.log, since console.warn triggers a YellowBox error that will be visible while running the app on your phone in debug mode.

Robbie Milejczak
  • 5,664
  • 3
  • 32
  • 65
  • I tried running this command ( adb reverse tcp:8081 tcp:8081 ) in terminal, it says command not found. Also, I am new to react and new to app-development, so if there is something else needs to done to run that command then please let me know. Thank you! – Neha Dec 28 '18 at 16:50
  • I also tried using, console.warn instead of console.log, nothing showed up anywhere. – Neha Dec 28 '18 at 16:51
  • hm are you using `Expo` by chance? if so you should look here: https://docs.expo.io/versions/latest/workflow/debugging if you don't have `adb` installed then you are most likely using `Expo`. If you don't have `adb` installed and you are not using `Expo` then you need to go through the `apps with native code` setup process – Robbie Milejczak Dec 28 '18 at 17:48
0
  1. Run app in mobile using 'react-native run-ios --device'
  2. Shake your device, this will open a action sheet menu like :-enter image description here
  3. Click debug JS Remotely this will open url like :8081/debugger-ui/ in your browser.
  4. right click on that page and select inspect menu.
  5. now select console tab and here your log will be displayed like enter image description here
Ankit Sharma
  • 251
  • 2
  • 9