Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is console.log() showing react_devtools_backend.js:4049 instead of the file and line number?

When I console.log(), the Chrome console gives the log but instead of showing the file and line number it just says react_devtools_backend.js:4049. How do I get the console to show the file and line number when I console.log()?

screenshot of console output showing "react_devtools_backend.js:4049" in place of a correct file and line number

like image 575
Abby Zhang Avatar asked Sep 06 '21 08:09

Abby Zhang


People also ask

What is the difference between console log and console info?

Technically console. debug() console.info() and console. log() are identical - the only difference is that debug messages are hidden by default and log messages are visible in the recent versions of Chrome (to see debug messages, you have to set the log level to Verbose in the Devtools).

What is the use of console log in react JS?

log() is one of the most useful functions you'll ever use. It allows you to debug, create proof of concepts, and even add functionality to a web app.


8 Answers

I was able to fix it in my console by adding the file to my Framework Ignore List in Chrome. Steps:

Console -> Gear icon (top right) -> Settings -> Framework Ignone List.

Add react_devtools_backend.js to the list and the console.log should start showing the correct mapping again.

screenshot of Framework Ignore List in Chrome Settings

like image 95
Sean Avatar answered Oct 26 '22 19:10

Sean


Disable the React Devtools extension in your browser.

It looks like that extension needs a fix.

like image 40
Ziarno Avatar answered Oct 26 '22 21:10

Ziarno


To add a bit more context apparently "it doesn't need a fix" as it's working as intended as per version 18 of 1st of September 2021. See comment of one of the developers on the React GitHub issue.

Quoting here in case you don't want to check the log or it gets deleted:

As of the version 18 release, DevTools always overrides the native console to either dim or suppress StrictMode double logging. (Before it only did it if you enabled a feature like component stacks.)

The major unfortunate drawback of this overriding is that it changes the location shown by the browser's console as reported in this issue.

So I guess that until they change their minds or browsers provide better support, it's time to switch off the extension.

like image 31
Alex Lillo Avatar answered Oct 26 '22 19:10

Alex Lillo


We can use

console.info(data)

instead of

console.log(data)
like image 18
Aleksandr Zelenskiy Avatar answered Oct 26 '22 19:10

Aleksandr Zelenskiy


actually it can be disabled in "Components tab" use "Gear" icon there image

and check "Hide logs during second render in Strict Mode" on the "debugging" tab.

image

like image 12
Dmitry Avatar answered Oct 26 '22 19:10

Dmitry


I have the same problem since yesterday in both Edge & Chrome, not exactly a solution just a temporary workaround: just disable the react-devtools extension from your browsers extensions.

like image 6
Userrrfriendly Avatar answered Oct 26 '22 20:10

Userrrfriendly


This may be due to the source map option disabled in webpack config file. You need to change your devtool in webpack config as

devtool: "source-map"

or you can control source map generation according to your need. check the documentation of devtool webpack

like image 2
Sudip Thapa Avatar answered Oct 26 '22 19:10

Sudip Thapa


This may happen if you are using React devtools extension in chrome. simply just go to chrome://extensions/ and check, If found then remove it. In my case it worked.

like image 1
shrinath deshmukh Avatar answered Oct 26 '22 19:10

shrinath deshmukh