我有一个Typescript项目,启动时如下所示:
ts-node-dev --preserve-symlinks --inspect=0.0.0.0 -- src/server.ts我可以用Visual Studio代码调试它,但是调试器在错误的行处中断。我能想到的唯一合理的解释是ts-node-dev没有将调试器指向源代码映射(它们就在那里)。
如何正确调试ts-node-dev执行的Typescript代码?
发布于 2021-09-19 07:41:40
在vs代码中使用ts-node-dev附加和启动调试器的调试配置:
package.json:
{
"scripts": {
"dev:debug": "ts-node-dev --transpile-only --respawn --inspect=4321 --project tsconfig.dev.json src/server.ts",
"dev": "ts-node-dev --transpile-only --respawn --project tsconfig.dev.json src/server.ts",
}
}launch.json:
{
"version": "0.1.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "Attach to dev:debug",
"protocol": "inspector",
"port": 4321,
"restart": true,
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "launch",
"name": "Debug",
"protocol": "inspector",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "npm",
"runtimeArgs": ["run-script", "dev"]
}
]
}发布于 2021-06-15 21:51:46
我也有同样的问题,这让我来到了这个(旧的)帖子。我在https://gist.github.com/cecilemuller/2963155d0f249c1544289b78a1cdd695找到了我的问题的解决方案,所以我把它贴在这里,以防其他人发现自己在这里!
这个VS代码配置允许我在TypeScript代码中的正确行上的断点处停止:
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
"args": ["src/script.ts", "--example", "hello"],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
}
]
}https://stackoverflow.com/questions/61190639
复制相似问题