imp*_*ion 6 debugging typescript visual-studio-code vscode-tasks
我想在打字稿文件上调试和设置断点,并在使用 VSCode 调试器配置进行更改(如 nodemon 监视更改)时重新启动调试器。
到目前为止,我实现了通过 VSCode 运行并在没有调试的情况下重新启动更改。
这是我的launch.json:
{
"name": "Launch Typescript Server Debugger",
"request": "launch",
"type": "node",
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"stopOnEntry": false,
"program": "${workspaceRoot}/node_modules/nodemon/bin/nodemon",
"args": [
"--watch",
"src/**/*.ts",
"--ignore",
"src/**/*.spec.ts",
"--exec",
"${workspaceRoot}/node_modules/.bin/ts-node",
"--inspect",
"src/app.ts"
],
"restart": true,
"env": { "NODE_ENV": "dev"}
}
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Ant*_*gov 11
想知道为什么这么多 WTF 评论这个完全自然的问题。这是我的制作方法:
我们需要nodemon在更改时重新启动我们的应用程序,我们需要ts-node/register来运行我们的 typecrypt,我们需要设置 vscode 的启动器脚本以在重新编译应用程序后重新附加调试器。因此,安装 nodemon、ts-node 并将此脚本添加到 package.json:
"watch:debug": "nodemon --inspect=5858 -e ts,tsx --exec node -r ts-node/register ./src/index.ts"
Run Code Online (Sandbox Code Playgroud)
然后在launch.json中添加配置:
{
"name": "Attach to Process",
"type": "node",
"request": "attach",
"restart": true,
"port": 5858,
"outFiles": [],
"sourceMaps": true
},
Run Code Online (Sandbox Code Playgroud)
就是这样,现在我可以使用yarn watch:debug启动我的应用程序并附加调试器。如果您仍然遇到问题,请在此处查看我的 Github 存储库。
你绝对应该检查ts-node-devnodemon ,恕我直言,它比观看编译更快,因为它在重新启动之间共享Typescript 编译过程。下面是示例 vscodelaunch.json配置,可让您设置断点(调试)以及在更改时重新加载。
{
"version": "1.0.0",
"configurations": [
{
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"name": "Local Server",
"restart": true,
"request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/ts-node-dev",
"skipFiles": [ "<node_internals>/**" ],
"type": "node",
"runtimeArgs": [ "--respawn" ],
"args": [ "${workspaceFolder}/src/script/local.server.ts" ]
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在您可以按F5或使用调试窗格开始调试/实时重新加载。
如果你碰巧用它来开发,我为此封装了一个小型库aws lambda
https://github.com/vcfvct/ts-lambda-local-dev
很不清楚你到底在问什么,但这可能会有所帮助。尝试将这些配置添加到您的
{
"name": "Current TS File",
"type": "node",
"request": "launch",
"args": ["${relativeFile}"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector",
}
Run Code Online (Sandbox Code Playgroud)
这个配置:
我怀疑你错过了
"runtimeArgs": ["--nolazy"]
Run Code Online (Sandbox Code Playgroud)
在您启动配置中。
| 归档时间: |
|
| 查看次数: |
5686 次 |
| 最近记录: |