使用visual studio代码的0.3版本,我不确定如何启用sourcemaps并调试ts文件

我得到以下错误can't launch program '/Projects/app-server/server.ts'; enabling source maps might help

如何启用sourcemaps和typescript调试.Sourcemap在我的

tsconfig.json

{
    "compilerOptions": {
        "target": "ES5",
        "module": "commonjs",
        "sourceMap": true
    }
}

emits json

{
    "version": "0.1.0",
    // List of configurations. Add new configurations or edit existing ones.  
    // ONLY "node" and "mono" are supported, change "type" to switch.
    "configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Launch server.ts",
            // Type of configuration. Possible values: "node", "mono".
            "type": "node",
            // Workspace relative or absolute path to the program.
            "program": "server.ts",
            // Automatically stop program after launch.
            "stopOnEntry": true,
            // 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,
            // Environment variables passed to the program.
            "env": { }
        }, 
        {
            "name": "Attach",
            "type": "node",
            // TCP/IP address. Default is "localhost".
            "address": "localhost",
            // Port to attach to.
            "port": 5858
        }
    ]
}

推荐答案

这个配置对我来说很好:

项目分布

|-- .vscode
    |----- emits json
|-- bin
    |----- app.js
    |----- app.js.map
|-- src
    |----- app.ts
|-- node_modules
    |-- [..]
|-- tsconfig.json
|-- [...]

这个 idea 是在src文件夹下编译typescript,并将其放在bin文件夹下.

tsconfig.json

激活sourceMap选项很重要.

{
    "compilerOptions": {
        "emitDecoratorMetadata": true,
        "module": "commonjs",
        "target": "ES5",
        "outDir": "bin",
        "rootDir": "src",
        "sourceMap": true
    }
}

emits json

==编辑====

这是我目前在Visual Studio Code v1中使用的配置:

{
    "version": "0.2.0",
    "configurations": [
        {
            "args": [],
            "cwd": "${workspaceRoot}",
            "env": {
                "NODE_ENV": "development"
            },
            "externalConsole": false,
            "name": "DEBUG",
            "outDir": "${workspaceRoot}/bin",
            "preLaunchTask": "compile",
            "program": "${workspaceRoot}/src/app.ts",
            "request": "launch",
            "runtimeArgs": [
                "--nolazy"
            ],
            "runtimeExecutable": null,
            "sourceMaps": true,
            "stopOnEntry": false,
            "type": "node"
        },
        {
            "name": "Attach",
            "type": "node",
            "request": "attach",
            "port": 5858
        }
    ]
}

注意:如果使用任何任务运行程序as gulp,键preLaunchTask非常有用,因为IDE能够按名称检测其任务.

run

  1. 编译ts(输入终端rm -r bin/ ; tsc或执行编译任务)
  2. 在视觉代码播放Launch type中(我们的配置名称)
  3. 享受

调试

Typescript相关问答推荐

我可以让Typescript根据已区分的联合键缩小对象值类型吗?

类型缩小对(几乎)受歧视的unions 不起作用

替换类型脚本类型中的多个特定字符串

使用前的组件渲染状态更新

对于使用另一个对象键和值类型的对象使用TS Generics

防止获取发出不需要的请求

如何用不同的键值初始化角react 形式

TypeScript类型不匹配:在返回类型中处理已经声明的Promise Wrapper

泛型和数组:为什么我最终使用了`泛型T []`而不是`泛型T []`?<><>

学习Angular :无法读取未定义的属性(正在读取推送)

使用打字Angular 中的通用数据创建状态管理

如何在typescript中为this关键字设置上下文

如何将父属性类型判断传播到子属性

有没有一种方法可以确保类型的成员实际存在于TypeScript中的对象中?

为什么我的导航在使用Typescript的React Native中不起作用?

对象类型的TypeScrip隐式索引签名

在Cypress中,是否可以在不标识错误的情况下对元素调用.Click()方法?

如何键入并类型的函数&S各属性

使用来自API调用的JSON数据的Angular

在REACT查询中获取未定义的isLoading态