pailhead
pailhead

Reputation: 5421

Chrome dev tools, unusual behavior, shows variables as undefined but still accesses the members

I might need some help with better explaining and defining this problem, as is i only know this happens in chrome devtools, that the code i'm looking at has been compiled with parcel, and that i'm using some version of typescript after 4.4.

I've stepped a few lines after 500 here, and const parsed shows as undefined both when i hover and in the scope window. If it were indeed undefined, parsed.type should have thrown, as well as the line i'm at - 506 where it accesses .value

enter image description here

However, after a few more steps, i land on 507 (!) and now i can see that there is indeed something in parsed and that there must have been before stepping (the scope window shows parsed as {type: 'ok', value: 'custom-plot'}.

enter image description here

I have very limited experience with parcel, but i'm positive that i've been able to get a better experience debugging typescript when nailing a proper setup for webpack. Where and how could i even start debugging this?

At a minimum, i'd like to tell the debugger to move past 500, and really truly see whats in that variable after that assignment.

EDIT

I've upgraded parcel and got this to behave better out of the box, still im curious which part of the tool chain was causing this.

Upvotes: 2

Views: 660

Answers (1)

Andrew Stegmaier
Andrew Stegmaier

Reputation: 3777

It probably was parcel, or the tools used internally by parcel (swc/babel/tsc, depending on your setup). (Although this a guess - hard to know for sure without a full repro that I could debug). Parcel is responsible for generating the source maps, and bugs in source maps can easily cause the kinds of issues you saw - where there's a mismatch between the line of .ts code that the debuggers says it's stopped on, and what really appears to be happening as far as variables, control flow, etc.

The fact that upgrading parcel caused the problem to go away supports this theory. You can also see a number of source-map related bugs being fixed in the parcel changelog. If you continue to experience issues like this in the future, I'd suggest trying to create a simplified reproduction and filing a bug with parcel.

Upvotes: 2

Related Questions