【问题标题】:Cannot Launch and Debug TypeScript Using Node无法使用节点启动和调试 TypeScript
【发布时间】:2018-02-22 16:30:17
【问题描述】:

我们正在设置一台新的 OSx 机器,并在尝试启动和调试基于 TypeScript 的节点应用程序时收到此消息:

无法启动程序'/Projects/is/0.0.34/server/server/server.ts'; 设置“outDir 或 outFiles”属性可能会有所帮助。

一年多来,我们一直在使用相同的启动配置,并且我们没有将输出写入单独的目录,因此不需要设置“outFiles”。该程序在命令提示符下运行良好。但是,尝试在 VsCode 中启动应用程序现在返回上述错误。我们最近确实从 v7.3.0 升级到了 Node v8.5.0。根据文档,这应该仍然有效。有关此问题的其他帖子涉及将源(和源映射)写入不同目录所产生的问题。

launch.json

{
    "configurations": [
        {
            "name": "Launch Program",
            "type": "node",
            "request": "launch",
            "program": "${workspaceRoot}/server/server.ts",
            "cwd": "${workspaceRoot}"
        }
    ]
}

这是 tsconfig:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "sourceMap": true,
        "watch": true,
        "allowUnreachableCode": true,
        "noImplicitUseStrict": true
    }
}

【问题讨论】:

    标签: node.js typescript visual-studio-code


    【解决方案1】:

    使用 VsCode 的 Node + TypeScript 项目现在似乎需要“outFiles”设置。我将它添加到了 launch.json 并且它现在可以工作了。

    "outFiles": [
        "${workspaceRoot}/**/*.js"
    ]
    

    【讨论】:

      【解决方案2】:

      像这样使用你的 launch.json 文件。

      {
      // Use IntelliSense to learn about possible attributes.
      // Hover to view descriptions of existing attributes.
      // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
      "version": "0.2.0",
      "configurations": [ 
      
      {
          "type": "node",
          "request": "launch",
          "name": "Launch Program",
          "program": "${workspaceFolder}/yourjsfile.js"
      },
          {
              "type": "node",
              "request": "launch",
              "name": "Launch Program",
              "program": "${file}",
              "outFiles": [
                  "${workspaceFolder}/**/*.js"
              ]
          }
      ]
      }
      

      【讨论】:

        猜你喜欢
        • 2018-01-10
        • 1970-01-01
        • 2018-10-16
        • 2017-01-29
        • 2020-08-16
        • 1970-01-01
        • 1970-01-01
        • 2019-05-13
        • 2022-06-16
        相关资源
        最近更新 更多