vscode 上调试js/ts的方法

对于TS,我用的是ts-node,npm全局安装,

launch.json:

复制代码
{
    // 使用 IntelliSense 了解相关属性。
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "ts-node Debugger",
            "type": "node",
            "request": "launch",
            "args": [
                "${workspaceRoot}/tsTest/test1.ts" // 入口调试文件
            ],
            "runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
            "sourceMaps": true,
            "cwd": "${workspaceRoot}",
            "protocol": "inspector",
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "runtimeExecutable": "C:/software/nvm/v16.10.0/node"//你的node安装目录
        }
    ]
}
复制代码

tsconfig.json:

复制代码
{
    "compileOnSave": false,
    "compilerOptions": {
        // other compiler options...
        "esModuleInterop": true,
        "module": "ESNext", // "module": "CommonJS" should work too
        "moduleResolution": "Node"
    },
    "include": ["src/*.ts", "tsTest/*.ts"],    //我要对哪些文件生效,这里我只要对tsTest和我src目录下的ts文件应用此配置
    "exclude": ["node_modules"],
    //这里可以不写
    "ts-node": {
        "esm": true,
        "experimentalSpecifierResolution": "node"
    }
}
复制代码

这里要注意的是,调试ts的话,要删除package.json中的

    "type": "module",
属性,不然会报
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts"
这样的错误
posted @   洛晨随风  阅读(356)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
历史上的今天:
2022-02-10 antd 的table 文本加入html渲染的方法
2020-02-10 vue 发布到iis/nginx调用post方法出现405的解决方案
2015-02-10 使用MSSQL,连接oracle,对oracle数据进行操作
2015-02-10 oracle出现的小问题
点击右上角即可分享
微信分享提示