我已经找遍了所有地方,但在VS代码中调试TypeScript仍然有问题。我已经阅读了this线程,但仍然不能命中TypeScript文件中的断点,命中.js文件中的断点一切正常。
这是我设置的最简单的"hello world“项目。
var消息: string = "Hello World";console.log(message);
{ "compilerOptions":{ "target":"es5","sourceMap":true } }
{ "version":"0.2.0","configurations":[{ "name":"Launch","type":"node","request":"launch","program":"${workspaceRoot}/app.js","stopOnEntry":false,"args":[],"cwd":"${workspaceRoot}","preLaunchTask":null,"runtimeExecutable":null,"runtimeArgs":"--nolazy“,"env":{ "NODE_ENV":”开发“},"externalConsole":false,"sourceMaps":true,"outDir":空}] }
我已经通过运行tsc --sourcemap app.ts
命令生成了js.map文件。
执行完所有这些步骤后,当我在Debug行上设置断点并从“console.log(message);
”选项卡启动程序(F5)时,该断点将灰显,并显示“由于未找到生成的代码而忽略断点(源代码映射问题?)”。我附上了我所观察到的截图:
我遗漏了什么?
编辑:
嗨,我还是被这个卡住了。我设法制作了一个正在命中断点的示例项目,但在我尝试将该项目复制到我的硬盘上的不同位置后,断点再次变成灰色,并且没有命中。我在此测试项目中所做的不同之处在于,通过使用tsc app.ts --inlinesourcemap
编译TypeScript文件来使用内联源地图
我将提到的示例项目上传到GitHub,以便您可以在here上查看它。
发布于 2016-12-10 10:18:32
"outFiles"
值应该与tsconfig.json
中为outDir
和mapRoot
设置的值相匹配,在本例中为${workspaceRoot}
,因此尝试使用"outFiles": "${workspaceRoot}/**/*.js"
这是我的tsconfig.json
{
"compilerOptions": {
"module": "commonjs",
"noImplicitAny": true,
"removeComments": true,
"preserveConstEnums": true,
"sourceMap": true,
"target": "es6",
"outFiles": ["${workspaceRoot}/compiled/**/*.js"],
"mapRoot": "compiled"
},
"include": [
"app/**/*",
"typings/index.d.ts"
],
"exclude": [
"node_modules",
"**/*.spec.ts"
]
}
和launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceRoot}/compiled/app.js",
"cwd": "${workspaceRoot}",
"outDir": "${workspaceRoot}/compiled",
"sourceMaps": true
}
]
}
下面是一个小项目,您可以在其中看到所有设置为https://github.com/v-andrew/ts-template的参数
发布于 2016-05-01 22:49:51
我是在寻找类似问题的解决方案时遇到这个问题的。尽管与OP的问题不同,但它可能会对其他人有所帮助。
背景:我正在关注Visual Studio Code HelloWorld example,发现自己无法在断点上停下来。
我解决这个问题的方法是更改.vscode/launch.json
,以便设置启动配置下的"sourceMaps": true
属性(它将默认设置为false)。
发布于 2016-03-15 17:11:30
我认为问题可能出在launch.json的“程序”部分。像这样试一下:
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch",
// Type of configuration.
"type": "node",
"request": "launch",
// Workspace relative or absolute path to the program.
"program": "${workspaceRoot}/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": "${workspaceRoot}",
// 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": "${workspaceRoot}"
}
https://stackoverflow.com/questions/36006303
复制相似问题