使用VS Code、TypeScript和Node.js的断点位置不正确
Incorrect breakpoint location using VS Code, TypeScript and Node.js
尝试在VS代码中使用TypeScript调试节点应用程序。
问题是调试器没有在源代码中的正确位置停止。
应用
class Foo
{
doSomething(){
console.log("TEST");
}
}
var foo = new Foo()
foo.doSomething();
tsconfig.json
{
"compilerOptions": {
"sourceMap": true,
"target": "ES5",
"module": "commonjs"
}
}
launch.json
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration.
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app.ts",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": ["--nolazy"],
// Environment variables passed to the program.
"env": {
"NODE_ENV": "development"
},
// Use JavaScript source maps (if they exist).
"sourceMaps": true,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": null
},
tasks.json
// A task runner that calls the Typescript compiler (tsc) and
// compiles based on a tsconfig.json file that is present in
// the root of the folder open in VSCode
{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "tsc",
// The command is a shell script
"isShellCommand": true,
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Tell the tsc compiler to use the tsconfig.json from the open folder.
"args": ["-p", "."],
// use the standard tsc problem matcher to find compile problems
// in the output.
"problemMatcher": "$tsc"
}
问题是,如果我在"console.log("test");"行设置断点,调试器会跳下两行并错过我的断点。
知道为什么会发生这种事吗。据我所知,应该可以调试用typescript编写的节点应用程序。
我怀疑原因是app.ts
在某个时刻发生更改时,您的app.js
和app.map.js
没有更新。
每次运行调试器之前都应该运行tsc任务,以确保生成的JavaScript文件反映您在TypeScript文件中所做的更改。
这个(非常常见)用例的简单项目模板可以在https://github.com/jyuhuan/node-ts.它定义了一个tsc任务,用于监视TS文件的任何更改,使生成的JS文件始终保持最新。
相关文章:
- 可以't让我的if语句处理js中的html表单输入
- 使用agility.js进行页面布局和合成
- 使用Clipboard.js复制span文本
- 使用JS如何动态更改显示的html文件中的文本背景颜色
- 强制模板刷新ember.js
- 如何编写HTML输入的JS内联
- Angular JS IE9 Hashbang url rewriting
- 使用JS将数组转换为json对象
- Node.js v6.2.0类扩展不是函数错误
- 如何使用SeleniumWebDriver通过断点调试Node.js上的javascript测试
- Eclipse with Webclipse - JS 调试器不会在断点处停止
- 我的启动项目中的JS文件的另一个“断点当前不会被命中”错误
- JS如何以编程方式创建断点
- 使用VS Code、TypeScript和Node.js的断点位置不正确
- Webstorm node.js远程调试不会跳转到断点
- 在某个断点通过JS自动更改CSS
- 有没有办法在 chrome 开发工具中为每个 js 行设置断点
- 节点.js:setInterval 中的断点
- 是否有一种方法可以在JS变量上设置断点
- Ember js controllerSetup with call to async model使用断点工作,但不能没