I'm trying to debug my app created with create-react-app
for the Google bot.
TL:DR: I need to add my error to the DOM so it's visible in the Google bot rendering. The problem is how do I get the same accurate (via source maps) file/line/column numbers that React displays in dev to be displayed in a DOM node.
On Google documentation for debugging rendering, they provide a snippet using a global window.addEventlistener('error')
to add the error to the DOM so it's visible in the rendered screenshot that Google bot generates.
However, when I try this on development, I'm getting this as the first line of the stack trace :
at Home.render (http://localhost:3000/static/js/main.chunk.js:17125:34)
So it's giving me the right function, but the source file and line/column numbers are wrong.
I'm able to see the correct error via the development error display that I assume is something from create-react-app
Notice that it gives the error in src/containers/Home/Home.js
on line 70
compared to the DOM pre output.
Is there a way to get the same accurate result in my DOM pre output ?
try{/*...*/}catch(e){ console.log(e.stack) }
? – Portacreate-react-app
must be using under the hood. However I wonder if there can't be an easier solution, a library maybe, that can take an error and source map and 'do the translation' @Copp Yes I understand the Google bot won't be able to do this, so I basically need to use my JS code to do the translation taking the error and source map file, then displaying this in the DOM – Impetratesudo
:/ I found another SO question that seems to be the missing piece : #32642584 – Impetrateredbox-react
but tonpm
and WSL – Impetratenpm
problem and it's working withredbox-react
! I can now see the detailed and accurate errors on the Google bot rendering :D Feel free to post an answer so I can accept it – Impetrate