Debugging TypeScript code with Visual Studio

前端 未结 6 1447
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 20:13

Is there a way to debug TypeScript source in Visual Studio (instead of debugging the generated javascript)?

From the TypeScript language specifications:

6条回答
  •  一整个雨季
    2020-11-30 20:56

    Debugging typescript with Visual Studio works with the right settings. (In previous versions of VS I face problems sometimes, below is how it works fine with VS 2015 CTP 6)

    1. First you make sure that you create source maps when compiling typescript to javascript. So you should have an xxx.js.map file near every xxx.js.

      Getting source maps by running the typescript compiler outside of Visual Studio does not cause any difficulty, at the tsc command line add

      --sourcemap %1.ts
      

      your gulp script will usually create sourcemaps by default.

    2. Configure your web application in Visual Studio.

      Set Internet Explorer as the start browser. I got it working only with IE and dont think any other browser will work.

      In the project properties go to the "Web" tab and configure the "Debuggers" section at the bottom: Disable all debuggers! This is counter intutitive and you might see this error message:

      You have attempted to start the debugger, but based on your current debug settings on the Web properties page there is no process to debug. This occurs when the "Don't open a page. Wait for a request from another process" option is selected, and ASP.NET debugging is disabled. Please check your settings on the Web properties page and try again.

      As the error message says, the Start Action at the top of the Web properties should be another option, like "Current page".

      Set breakpoints in your ts code inside Visual Studio now or later.

      Hit F5

    While you can use the Visual Studio Editor to debug and edit ts files, "Edit and Continue" will not work, there is currently no browser that can reload js and js.map files and continue. (Correct me anyone if I am wrong and I will be happy.)

提交回复
热议问题