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"
这样的错误
积累小的知识,才能成就大的智慧,希望网上少一些复制多一些原创有用的答案
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 【自荐】一款简洁、开源的在线白板工具 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出现的小问题