react-native: console.log commands are not shown their code line locations
After 0.61.x releases on the debug mode console.log
commands are not showing their code line locations. They always shown at ... Project Directioy ...\projectName\node_modules\react-native\Libraries\Core\setUpDeveloperTools.js:73
directory.
For example; Before update:
After update:
Is this a bug? If it’s not previous version was way more useful for variable, data or etc… tracking.
Versions:
"react": "16.9.0",
"react-native": "0.61.1"
Environment:
[skip envinfo]
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 19
- Comments: 36 (14 by maintainers)
Commits related to this issue
- Don't wrap console methods for metro logging in Chrome debugger Summary: This diff fixes an issue reported in https://github.com/facebook/react-native/issues/26788 where logs in the Chrome console we... — committed to rickhanlonii/react-native by rickhanlonii 5 years ago
- Don't wrap console methods for metro logging in Chrome debugger (#26883) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/26883 This diff fixes an issue reported in http... — committed to facebook/react-native by rickhanlonii 5 years ago
- Don't wrap console methods for metro logging in Chrome debugger (#26883) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/26883 This diff fixes an issue reported in http... — committed to facebook/react-native by rickhanlonii 5 years ago
- Don't wrap console methods for metro logging in Chrome debugger (#26883) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/26883 This diff fixes an issue reported in http... — committed to react-native-tvos/react-native-tvos by rickhanlonii 5 years ago
This is fixed by https://github.com/facebook/react-native/pull/26883
That diff will revert this back to showing “YellowBox.js”:
This will stay the case until Chrome exposes a way for us to ignore our wrapping frame (see here).
Until then, if you want to see the true frame, you can blackbox
YellowBox.js
(or any script) and Chrome will know to skip that frame:Note: The regexes to use are
/YellowBox\.js$
and/setUpDeveloperTools\.js$
Note: Notice that
App.js
is referenced here instead ofYellowBox.js
You can read more about Chrome Blackboxing here
I also use Chrome Debugger tools, It feels simpler… if this decision can be discussed, count my vote for allowing to see logs like before without having to install React DevTools.
Thanks for the support, like @acoutts said this fixed the issue. We waiting for merge.
Closing the issue for fixed, have a great day you all, bugless coding ! 🍺
Manually modify the react native core file in node_modules as per the commit here: https://github.com/facebook/react-native/pull/26883/commits/77acfd74b6324c651e814c4a1e032471952dfce2
I just applied this patch and chrome console logs work again for me and it’s showing the correct files/ line numbers as before.
I’m not sure why and how it’s happening but it would be more better to work like other version.
My takeaway from this is that the current default is probably not working out very well for folks, so I’ll change it (off instead of on). Sorry for the inconvenience.
I was tracking logs on Google Chrome Debugger, not React Devtools, so there is no way to disable such as you mention it. But anyway, like @acoutts said when I try to devtools I got incompatible errors.
I’m getting the same result in my console with the newer versions of RN.
The fix was merged, we went with a strategy that was a bit better than the original patch tested above so please check it out and let me know if you have any questions https://github.com/facebook/react-native/commit/42ac240bceb104474494c6007df0089baec00f7a
I think there’s a misunderstanding.
Could it be that console.logs are being eaten by the thing that sends them to Metro? So then it wouldn’t be React DevTools-related at all.
In that case ideally the fix would be to somehow detect if we’re in a “rich console” environment like Chrome or not. When we are, don’t hijack console to send logs to Metro.
A possible way to detect that could be to check whether console methods are native or RN polyfill. Maybe by toString-ing them. Or by checking for some Chrome specific property on console. Need to make sure the fix doesn’t give a false positive for Hermes.
Thanks @bvaughn. I think most of the confusion comes from most people not using react devtools but just using Chrome (the thing that opens by default when you enable debugging).
0.61.3 - Still shows
setUpDeveloperTools.js:73
… I was with the idea that the fix was already merged for this release, did I miss something?It will be merged when it’s ready. Likely next week.
Checking whether console is native or not and skipping the Metro logging setup makes sense to me. Do you wanna send a PR for that?
Follow up clarification question for @ezranbayantemur @ledzep9012 etc: Why was the “before” behavior of showing
YellowBox.js
(already a React Nativeconsole
override) preferable to the new location of showing the DevTools backend? Neither is the original place the error/warning was logged.@motiz88 It does not, although I did open a discussion issue about this type of thing: https://github.com/whatwg/console/issues/163
It got a little attention initially but seems to have fizzled 😞
@ezranbayantemur @motiz88 This is a React DevTools v4 feature, so it would be expected to impact RN v61+.
You should be able to disable it in the general settings.