简体   繁体   English

如何在Visual Studio Code中成功调试打字稿?

[英]How do you debug typescript in Visual Studio Code successfully?

I notice if you are using Node Package Manager generally you can have your package.json have something like this: 我注意到,如果您通常使用Node Package Manager,则可以让package.json具有以下内容:

(dependencies and devDependencies omitted)..
"scripts": {
    "start": "concurrently \"npm run tscwatch\" \"npm run lite\" ",
    "tsc": "tsc",
    "tscwatch": "tsc -w",
    "lite": "lite-server",
    "typings": "typings",
    "postinstall": "typings install"
  }

Then you just get to the level of the folder you are at and type in 然后,您只需进入您所在文件夹的级别并输入

npm install

Then 然后

npm start

And lite server hosts your application and typescript compiles to javascript. 精简版服务器托管您的应用程序,并将打字稿编译为javascript。 Provided that you have ran the equivalent of your typescript configurations and have a valid tsconfig.json. 前提是您已经运行了与打字稿配置相同的配置,并且具有有效的tsconfig.json。 That aside I am wanting to debug the Typescript and just running into wall after wall getting it working. 除此之外,我想调试Typescript并让它工作正常。 I know you can add 'launch.json' that VS Code uses to do MANY types of abilities to start programs. 我知道您可以添加VS Code用于启动程序的许多类型的功能的“ launch.json”。 And a lot of them work fine for simple apps I find online, but not Angular as I am using it. 它们中的许多对于我在网上找到的简单应用程序都可以正常工作,但不适用于我正在使用的Angular。 But when I try to do an NPM Start in the launch.json like: 但是,当我尝试执行NPM时,请在launch.json中启动:

 {
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM ProAngular Example",
        "runtimeExecutable": "npm",
        "args": ["${relativeFile}"],
        "runtimeArgs": [
            "start"
        ]
    }

It will run but then attempt to open Visual Studio Professional(may not be the case for others) and then have an error like: "Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:(port)). I have tried other configs for NPM for launch and other things. I just want to debug the Typescript when it is done with Angular, is that possible in VS Code? 它将运行,但随后尝试打开Visual Studio Professional(其他情况可能并非如此),然后出现如下错误:“无法连接到运行时进程,在10000毫秒后超时-(原因:无法连接到目标:connect ECONNREFUSED 127.0.0.1:(port))。我已经尝试了NPM的其他配置以进行启动和其他操作。我只是想在用Angular完成调试Typescript时,在VS Code中可以吗?

Follow the below instructions in VSCode: 请按照VSCode中的以下说明进行操作:

1- Download the latest release of VS Code and install the Chrome debugger 1-下载最新版本的VS Code并安装Chrome调试器

2- Make sure Chrome is at least version version 59 (see issue ) 2-确保Chrome的版本至少为59版(请参阅问题

3- Create your Angular app using angular-cli 3-使用angular-cli创建Angular应用

4- Create a launch.jsonfile to configure the VS Code debugger and put it inside .vscode in your root folder. 4-创建一个launch.jsonfile以配置VS Code调试器,并将其放在根文件夹中的.vscode中。

 { "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "Launch Chrome with ng serve", "url": "http://localhost:4200/#", "webRoot": "${workspaceRoot}" }, { "type": "chrome", "request": "launch", "name": "Launch Chrome with ng test", "url": "http://localhost:9876/debug.html", "webRoot": "${workspaceRoot}" } ] } 

  1. Start your Angular app by running ng serve in your favourite terminal. 通过在您喜欢的终端中运行ng serve来启动Angular应用。

  2. Start debugging in VS Code by pressing F5 or going to the debug section select Launch Chrome with ng serve followed by clicking the green debug icon. 通过按F5开始在VS Code中进行调试,或转到“调试”部分,选择“ Launch Chrome with ng serve然后单击绿色的调试图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Visual Studio Code中使用Typescript进行TDD? - How to do TDD with Typescript in Visual Studio Code? 如何在Visual Studio代码中调试Angular2 TypeScript应用程序? - How to debug an Angular2 TypeScript application in Visual Studio Code? 使用 Visual Studio Code 调试和运行 Angular2 Typescript? - Debug & Run Angular2 Typescript with Visual Studio Code? Visual Studio代码中Ionic2-Angular2应用程序的Typescript调试 - Typescript debug for Ionic2-Angular2 application in Visual Studio code 您如何调试 Visual Studio + Angular + Firebase + Chrome(浏览器或应用程序不安全错误)? - How do you debug Visual Studio + Angular + Firebase + Chrome (browser or app not secure error)? 使用 Visual Studio Code 进行调试不起作用 - Debug with Visual Studio Code not working 如何在Docker容器Visual Studio Code中调试Angular应用? - How to debug Angular app in a Docker container Visual Studio Code? 如何使用Visual Studio Code调试Angular 4单元测试 - How to debug a Angular 4 unit tests using Visual Studio Code 如何从 Visual Studio Code 使用 Electron 和 Angular 调试应用程序? - How to debug an app with Electron and Angular from Visual Studio Code? 在可视化代码中调试 Angular/Typescript 将“_1”附加到变量 - Debug Angular/Typescript in visual code appends '_1' to variable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM