question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Line numbers in TypeScript broken for Chrome/VSCode debugging

See original GitHub issue

Describe the bug

I have a web application that does not use any frameworks such as React, Vue, etc. but does use TypeScript instead of normal JS files. When breakpoints are placed in my source code (using VSCode) the application does indeed break at the expected moment, and both Chrome Debugger and VSCode highlight the same (correct) lines but all Call Stack and variables info clearly shows the debugger is being referred to a different line. In addition, the line numbers reported for console.log statements (in Debug Console, for example) do not match the source code.

Reproduction

This is unfortunately tricky to reproduce because the problem seems to accumulate over a number of lines of code, and I’m not sure exactly where the misalignment happens. I will try to describe what I’m seeing as carefully as possible:

Line 201 is indeed the same line I set a breakpoint, and Chrome stops at this breakpoint and highlights the correct line: Screenshot 2021-11-25 at 13 23 07

Back in VSCode, the same (correct) line is still highlighted and the breakpoint has not moved, BUT notice how the “Variables” pane is showing information relating to a function a few lines down (removeControlledPlayer): Screenshot 2021-11-25 at 13 22 56

Notice how Chrome Debugger is doing the same thing - the Call Stack is showing the correct line number as per the sourcecode (201) but entirely the wrong function (removeControlledPlayer starts only from line 204 in the source code): Screenshot 2021-11-25 at 13 23 12

In what I assume is related, the line numbers for nearby console.log statements are curiously out. For example, the string “pointerup: remove!” is attributed to line 195 in the logs: Screenshot 2021-11-25 at 13 23 30

…But this statement actually appears on line 211 in the source code: Screenshot 2021-11-25 at 13 23 38

When bundling the exact same source code using another bundler (in my case, Parcel) the debugger works as normal and line numbers do not misalign like this.

Is there something wrong in ESBuild sourcemaps for TypeScript, which is what I believe Vite uses for TypeScript transpilation?

System Info

System:
    OS: macOS 11.6
    CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
    Memory: 101.52 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.16.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 7.21.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.55
    Firefox: 88.0.1
    Safari: 15.0
  npmPackages:
    vite: ^2.6.14 => 2.6.14

Used Package Manager

npm

Logs

No response

Validations

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:14
  • Comments:5

github_iconTop GitHub Comments

2reactions
cphillipscommented, May 7, 2022

In case it helps anyone, for my project removing multi-line imports worked around the issue.

import {
funcA,
funcB
} from './lib'

to

import { funcA, funcB } from './lib' 
0reactions
Flamencocommented, Sep 24, 2022

Here is a regex that I used to find multiline imports in my IDE

^import .*\{[^\}]+$
Read more comments on GitHub >

github_iconTop Results From Across the Web

vs code debugging has the wrong line numbers - Stack Overflow
I have a source file that starts with PHP, then html and JavaScript. When is debug the program, the Chrome developer tools does...
Read more >
TypeScript debugging with Visual Studio Code
We'll create a tiny web application to show client-side debugging in action. Run tsc to build the app and then test by opening...
Read more >
Debug SharePoint Framework solutions in Visual Studio Code
You also need Google Chrome or Microsoft Edge. Debug configurations. You can locate the debug configurations in the ./vscode/launch.json file ...
Read more >
awesome-vscode | A curated list of delightful VS Code ...
TypeScript. tslint (deprecated) - TSLint for Visual Studio Code. Debugger for Chrome. A VS Code extension to debug your JavaScript ...
Read more >
Vue + TypeScript & Debuggers - ckh|Consulting
Restart your app, launch Chrome in debug mode again (through VS Code's debug screen), and navigate to the App.vue Source Map. You will...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found