[英]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}" } ] }
Start your Angular app by running ng serve
in your favourite terminal. 通过在您喜欢的终端中运行ng serve
来启动Angular应用。
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.