console.log doesn't work with react-native

Jonis Maurin Ceará picture Jonis Maurin Ceará · Jul 16, 2018 · Viewed 17.7k times · Source

I'm starting with react-native and I'm getting this problem: I can't log to bundler metro server.

If I create my application using create-react-native-app, I can do 'console.log' and value are logged to metro bundler (running on port 8081).

But if I create my application with react-native init <project>, this doesn't work. To make console.log work, I need to open Chrome DevTools and set remote debug in application.

So my question is: is there any way to make native code to log in bundler console with console.log? I don't want to work with 'create-react-native-app' because it uses Expo and 'realm' database doesn't support expo.

I've tried with react-native 0.55.4 and 0.56, both in windows and linux.

Answer

David Nore&#241;a picture David Noreña · Jul 17, 2018

You can also see the console.log() outputs using these commands:

$ react-native log-android
$ react-native log-ios

Note: It also works to debug native errors, for example when you have a blank screen and metro bundler doesn't show errors neither.

For more information you can check this out