Value of “this” is incorrect when debugging Babel transpiled React with Chrome Devtools

Unfortunately this is a fact of life when using the debugger in Babelified code with Chrome. To implement arrow functions with the ECMAScript spec behavior, the this keyword needs to be transformed into a different name, and there’s currently no way to tell Chrome what do to for debugging. Firefox’s developer tools have a bunch of extra logic to address issues like this, so it may work properly if you’re using Firefox and enable to “Map Scopes” checkbox, but it can also be slower because it isn’t trivial.

One option would be to try to use the spec option of the arrow function transformation, which should make this behave better for debugging, but may not work in all cases.

"plugins": [
    ["transform-es2015-arrow-functions", {spec: true}]
]

Leave a Comment