【问题标题】:break points in the typescript source not working打字稿源中的断点不起作用
【发布时间】:2016-10-15 13:17:12
【问题描述】:

我正在开发一个节点模块和一个示例应用程序。我正在尝试将调试断点添加到模块中的源文件之一,但我无法让 VSC 识别它。使用最新版本的 Typescript 和 VSC。

编辑:这应该是一个节点应用程序,不用担心浏览器。

EDIT2: 这里是问题repo with problem. 的repo 这是我目前的设置

├── dist
│   ├── index.d.ts
│   ├── index.js
│   ├── index.js.map
│   ├── main.d.ts
│   ├── main.js
│   ├── main.js.map
├── examples
│   ├── index.js
│   └── package.json
├── gulpfile.js
├── package.json
├── src
│   ├── index.ts
│   ├── main.ts
├── tsconfig.json
├── tslint.json

我正在examples/index.js 中开发示例,并在src/main.ts 中设置断点

这是我的 VSC launch.json 配置

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Launch TypeScript",
      "type": "node",
      "request": "launch",
      "program": "${workspaceRoot}/examples/index.js",
      "sourceMaps": true,
      "outDir": "${workspaceRoot}/src",
      "args": [
        "--nolazy"
      ]
    }
  ]
}

我的 tsconfig.json

{
    "compilerOptions": {
      "target": "es2015",
      "module": "commonjs",
      "sourceMap": true,
      "outDir": "dist",
      "declaration": true,
      "rootDir": "src"
    },
    "exclude": [
      "node_modules",
      "examples",
      "dist"
    ]
}

我的任务

gulp.task('default', function () {
  var tsResult = tsProject.src('tsconfig.json')
    .pipe(sourcemaps.init())
    .pipe(ts(tsProject));

  return merge([
        tsResult.dts.pipe(gulp.dest('dist')),
        tsResult.js
        .pipe(sourcemaps.write('.', {includeContent: false, sourceRoot: 'src'}))
        .pipe(gulp.dest('dist'))
    ]);
});

源地图是如何放置的

{"version":3,"sources":["main.ts"],"names":[],"mappings":";CAAC,...CAAC","file":"main.js","sourceRoot":"src"}

【问题讨论】:

  • Typescript 文件永远不会被执行,它们会被转换为 Javascript,然后运行。我不确定你是否可以在 VS 中的 Javascript 文件中放置代码中断,但你可以在开发者工具中。
  • 我还要澄清一下,这些是节点应用程序
  • 哦,那我就不知道了,抱歉。

标签: javascript typescript visual-studio-code


【解决方案1】:

您可能需要将“outDir”更改为“${workspaceRoot}/dist”。 Node 调试器使用该标志来查找您生成的脚本。

【讨论】:

    【解决方案2】:

    Visual Studio Code 正在使用“程序”来引用相应“outDir”中的文件名“index.js”。在您的情况下,它正在寻找“dist/index.js”。

    有一个备用入口文件会导致混乱。为避免名称冲突,“examples/index.js”需要是“dist”中不存在的唯一文件名(exampleApp.js?)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-08-29
      • 2018-04-30
      • 1970-01-01
      • 2020-03-18
      • 1970-01-01
      • 2017-02-20
      • 2016-06-16
      • 2018-12-25
      相关资源
      最近更新 更多