【问题标题】:debugging typescript in vscode with autorestart使用自动重启在 vscode 中调试打字稿
【发布时间】:2017-12-08 03:20:40
【问题描述】:

我正在用 node 建立一个打字稿项目。

我可以使用launch.json 配置在 vs 代码中调试我的 main.ts 文件:

 {
        "type": "node",
        "request": "launch",
        "name": "Lancer le programme",
        "program": "${workspaceRoot}/src/main.ts",
        "outFiles": [
            "${workspaceRoot}/dist/**/*.js"
        ]
    }

这工作正常,但当我编辑 main.ts 时没有自动重启

为了实现自动重启,我在我的项目目录tsc --watch中启动,然后这个lauch配置:

    {
        "type": "node",
        "request": "launch",
        "name": "nodemon",
        "runtimeExecutable": "nodemon",
        "runtimeArgs": [
            "--debug=5858"
        ],
        "program": "${workspaceRoot}/src/main.ts",
        "outFiles": [
            "${workspaceRoot}/dist/**/*.js"
        ],
        "restart": true,
        "port": 5858,
        "console": "integratedTerminal",
        "internalConsoleOptions": "neverOpen",
        "sourceMaps": true
    },

当我编辑源文件时,上面的配置会自动重启,但是 vscode 调试器不再崩溃了……

有没有人实现:在 vscode 中使用自动重启调试 typscript?

【问题讨论】:

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


    【解决方案1】:

    这是我的launch.json

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "nodemon",
                "runtimeExecutable": "${workspaceFolder}/node_modules/nodemon/bin/nodemon.js",
                "program": "${workspaceFolder}/build/index.js",
                "restart": true,
                "runtimeArgs": [
                    "--debug=5858",
                    "--inspect-brk"
                ],
                "port": 5858,
                "console": "integratedTerminal",
                "internalConsoleOptions": "neverOpen"
            }
        ]
    }
    

    注意,prop program 必须表示编译好的js文件。在您的情况下,它是 ${workspaceRoot}/src/main.ts,但应该是 ${workspaceRoot}/*compile directory eg. build*/main.js

    还要确保打字稿将文件重新编译到目标目录。

    【讨论】:

    • 如果适用,请尝试描述您的配置的作用以及它与 OP 的不同之处,以便更容易理解您的解决方案的工作原理
    • 您的tsconfig.jsonnodemon.json 是什么样的?我收到File 'dist/file.js' is a Javascript file. Did you mean to enable the 'allowJs' option? 消息,因为当它应该编译并输出到 src 文件夹时,显示 nodemon 正在尝试启动 'tsc ./dist/file.js'。
    猜你喜欢
    • 2018-03-10
    • 2019-08-28
    • 2020-10-31
    • 1970-01-01
    • 2016-10-10
    • 2018-12-03
    • 2016-12-28
    • 2016-05-18
    相关资源
    最近更新 更多