首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >VS代码:“已忽略断点,因为找不到生成的代码”错误

VS代码:“已忽略断点,因为找不到生成的代码”错误
EN

Stack Overflow用户
提问于 2016-03-15 16:45:25
回答 19查看 51.6K关注 0票数 81

我已经找遍了所有地方,但在VS代码中调试TypeScript仍然有问题。我已经阅读了this线程,但仍然不能命中TypeScript文件中的断点,命中.js文件中的断点一切正常。

这是我设置的最简单的"hello world“项目。

  • app.ts:

var消息: string = "Hello World";console.log(message);

  • tsconfig.json

{ "compilerOptions":{ "target":"es5","sourceMap":true } }

  • launch.json

{ "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上查看它。

EN

回答 19

Stack Overflow用户

发布于 2016-12-10 10:18:32

"outFiles"值应该与tsconfig.json中为outDirmapRoot设置的值相匹配,在本例中为${workspaceRoot},因此尝试使用"outFiles": "${workspaceRoot}/**/*.js"

这是我的tsconfig.json

代码语言:javascript
复制
{
    "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

代码语言:javascript
复制
{
    "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的参数

票数 31
EN

Stack Overflow用户

发布于 2016-05-01 22:49:51

我是在寻找类似问题的解决方案时遇到这个问题的。尽管与OP的问题不同,但它可能会对其他人有所帮助。

背景:我正在关注Visual Studio Code HelloWorld example,发现自己无法在断点上停下来。

我解决这个问题的方法是更改.vscode/launch.json,以便设置启动配置下的"sourceMaps": true属性(它将默认设置为false)。

票数 17
EN

Stack Overflow用户

发布于 2016-03-15 17:11:30

我认为问题可能出在launch.json的“程序”部分。像这样试一下:

代码语言:javascript
复制
{
    // 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}"
}
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36006303

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档