简体   繁体   English

使用 typescript、nodemon 和外部项目在 vscode 中调试问题

[英]Debug issue in vscode with typescript, nodemon, and external projects

Thank you for anyone who is able to offer some insight about what is going on.感谢任何能够对正在发生的事情提供一些见解的人。 VS Code debugging has always been finicky, but I've got a situation that I think should work and it isn't. VS Code 调试一直很挑剔,但我遇到了一种我认为应该可行的情况,但事实并非如此。

Issue: I can set breakpoints in typescript and debug in 2 of my projects (server and common-internal), but not the 3rd (common-external).问题:我可以在 typescript 中设置断点并在我的 2 个项目(服务器和公共内部)中进行调试,但不能在第 3 个(公共外部)中进行调试。 Why can't I debug common-external, and how do I set it up so I can?为什么我不能调试 common-external,我该如何设置才能调试? VS Code cannot find the source to bind the breakpoint. VS Code 找不到绑定断点的源。

I've created a simple repo to reproduce the issue I'm seeing: https://github.com/snotmare/debug-issue我创建了一个简单的 repo 来重现我看到的问题: https://github.com/snotmare/debug-issue

Steps to reproduce:重现步骤:

  1. Clone repo克隆回购
  2. Run 3 init tasks (for common-internal, common-external, and server)运行 3 个初始化任务(用于公共内部、公共外部和服务器)
  3. Run 2 watch tasks (for common-internal and common-external)运行 2 个 watch 任务(用于 common-internal 和 common-external)
  4. Run the start server task运行启动服务器任务
  5. Run the debugger by attaching to the process通过附加到进程来运行调试器
  6. Set a breakpoint in server/src/index.ts (works)在 server/src/index.ts 中设置断点(有效)
  7. Set a breakpoint in common-internal/src/utils.ts (works)在 common-internal/src/utils.ts 中设置断点(有效)
  8. Set a breakpoint in common-external/src/external-utils.ts (does not work)在 common-external/src/external-utils.ts 中设置断点(不起作用)

Project setup:项目设置:

  • Typescript project with a utils class (common-internal). Typescript 项目与 utils class(公共内部)。
  • NodeJS server project that imports common-internal and common-external.导入 common-internal 和 common-external 的 NodeJS 服务器项目。
  • Both of these projects are within the same folder, with a.vscode folder at the same root for task and launch config.这两个项目都在同一个文件夹中,在同一个根目录下有一个 .vscode 文件夹用于任务和启动配置。

External project setup:外部项目设置:

  • Typescript project with utils class (common-external). Typescript 项目与 utils class(通用外部)。
  • This is setup exactly the same as common-internal, just renamed.这与 common-internal 的设置完全相同,只是重命名了。
  • This has its own.vscode folder for task config.这有自己的 .vscode 文件夹用于任务配置。

The server project depends on the 2 common projects like this:服务器项目依赖于 2 个常见项目,如下所示:

    "dependencies": {
        "common-internal": "file:../common-internal",
        "common-external": "file:../../common-external/common-external",
        "express": "4.18.2"
    },

I believe the issue is related to the folder structure, which looks like this:我认为问题与文件夹结构有关,如下所示:

root folder
- test-app
- - .vscode
- - common-internal
- - server
- common-external
- - .vscode
- - common-external

The folder structure needs to be this way because I want test-app to be in a git repo while common-external is in a separate git repo.文件夹结构需要这样,因为我希望 test-app 位于 git 存储库中,而 common-external 位于单独的 git 存储库中。

When I debug the server, why can't I set a breakpoint in common-external and debug it?调试服务器时为什么不能在common-external下断点调试? Thank you for your help!谢谢您的帮助!

Github issue for vscode: https://github.com/microsoft/vscode/issues/169033 vscode 的 Github 问题: https://github.com/microsoft/vscode/issues/169033

Ben

I found the solution for this by accident.我偶然找到了解决方案。 I was able to update the outFiles for my launch.json file to look for files outside of the workspace folder...我能够为我的 launch.json 文件更新 outFiles 以查找工作区文件夹之外的文件...

"outFiles": [
    "${workspaceFolder}/**/*.js",
    "${workspaceFolder}/../common-external/**/*.js",
    "!**/node_modules/**"
]

The vs code debugger is still finicky when it comes to my real (larger) project.当涉及到我的真实(更大)项目时,vs 代码调试器仍然很挑剔。 Sometimes it finds the source files, sometimes it doesn't.有时它会找到源文件,有时却找不到。 Has anyone else experienced performance issues with the debugger?其他人是否遇到过调试器的性能问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM