简体   繁体   English

vscode:使用nodemon启动时,无法使用Visual Studio代码中断任何断点

[英]vscode: Can't break on any breakpoint with Visual Studio code when launching with nodemon

VSCode Version: 1.10.2 OS Version: Windows 7 Profesionnal, SP1 Node version: 6.10.0 VSCode版本:1.10.2操作系统版本:Windows 7 Profesionnal,SP1节点版本:6.10.0

Hi everyone. 嗨,大家好。

I'm trying to debug typescript code (or javascript code) in server side with visual studio code, when launching it with nodemon. 我正在尝试用visual studio代码调试服务器端的typescript代码(或javascript代码),当使用nodemon启动它时。 I've added a new configuration in launch.json which looks like this: 我在launch.json中添加了一个新配置,如下所示:

{
      "type": "node",
      "request": "launch",
      "name": "Launch server with Nodemon",
      "runtimeExecutable": "nodemon",
      "runtimeArgs": [
        "--debug=5858"
      ],
      "program": "${workspaceRoot}/src/server.ts",
      "restart": true,
      "port": 5858,
      "console": "integratedTerminal",
      "internalConsoleOptions": "neverOpen",
      "outFiles": ["${workspaceRoot}/build/**/*.js"]
    }

I have a task in vscode that is running tsc that builds javascript files properly. 我在vscode中有一个运行tsc的任务,可以正确构建javascript文件。 This is my current task config: 这是我当前的任务配置:

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "0.1.0",
  "command": "tsc",
  "isShellCommand": true,
  "args": ["-p", "."],
  "showOutput": "silent",
  "problemMatcher": "$tsc"
}

The javascript files are generated as expected when I change a typescript file. 当我更改typescript文件时,会按预期生成javascript文件。 And the nodejs server is restarting as expected when a javascript file is generated. 并且当生成javascript文件时,nodejs服务器正在按预期重新启动。

But I am not able to break on any breakpoint (on typescript files or javascript files). 但是我无法打破任何断点(在打字稿文件或javascript文件上)。

Can you tell me please if it is an issue or if there is something I am missing ? 如果这是一个问题或者我有什么遗失的话,你能告诉我吗?

Thank you for your help 谢谢您的帮助

It looks that there is an issue in vscode (Issue opened by on github [here][1]) . 它看起来在vscode中存在问题(由github [here] [1]打开的问题)。 But for now, the workaround is to set the protocol in the configuration (launch.json) to "inspector". 但目前,解决方法是将配置(launch.json)中的协议设置为“inspector”。 With this option, the breakpoints is now reached properly. 使用此选项,现在可以正确地到达断点。

Also, change the "--debug=5858" in the "runtimeArgs" option to "--inspect=5858" 另外,将“runtimeArgs”选项中的“--debug = 5858”更改为“--inspect = 5858”

{
  "type": "node",
  "request": "launch",
  "name": "Launch server with Nodemon",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
  "runtimeArgs": [
    "--inspect=5858"
  ],
  "program": "${workspaceRoot}/src/server.ts",
  "restart": true,
  "port": 5858,
  "protocol": "inspector",
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "outFiles": ["${workspaceRoot}/build/**/*.js"],
  "sourceMaps": true
},

Also, after that, if you have a flashing message error telling you: 此外,在此之后,如果您有闪烁的消息错误告诉您:

Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858) 无法连接到运行时进程,10000毫秒后超时 - (原因:无法连接到目标:连接ECONNREFUSED 127.0.0.1:5858)

It means that your program is too short and that debugger has not enough time to break on your breakpoint. 这意味着您的程序太短,调试器没有足够的时间来破坏断点。 To resolve that, add a second runtime argument to option "runtimeArgs": "--debug-brk" and set too "stopOnEntry" option to true 要解决此问题,请向选项“runtimeArgs”添加第二个运行时参数: “ - debug -brk”并将“stopOnEntry”选项设置为true

The final configuration should looks like this: 最终配置应如下所示:

{
  "type": "node",
  "request": "launch",
  "name": "Launch server with Nodemon",
  "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
  "runtimeArgs": [
    "--inspect=5858",
    "--debug-brk"
  ],
  "stopOnEntry": true,
  "program": "${workspaceRoot}/src/server.ts",
  "restart": true,
  "port": 5858,
  "protocol": "inspector",
  "console": "integratedTerminal",
  "internalConsoleOptions": "neverOpen",
  "outFiles": ["${workspaceRoot}/build/**/*.js"],
  "sourceMaps": true
}

It should break on the first line of your entry javascript file. 它应该在您的条目javascript文件的第一行中断。 Then you can press F5 and it will reach your own breakpoint. 然后你可以按F5,它将到达你自己的断点。

If you don't want to press F5 each time you run your program, you can instead embed your main entry code inside a setTimeOut function with at least 1000 ms of timeout. 如果您不想在每次运行程序时按F5,则可以将主条目代码嵌入至少1000毫秒超时的setTimeOut函数中。

All these options will give enough of time to vscode to break on your breakpoints. 所有这些选项都会给你足够的时间来破坏你的断点。

://github.com/Microsoft/vscode/issues/23900 "GitHub Issue" ://github.com/Microsoft/vscode/issues/23900“GitHub Issue”

@ManfredSteiner @ManfredSteiner

I had this issue recently too. 我最近也遇到过这个问题。 I guess you've tried to break just in the beginning of your entry file (main.ts). 我猜你试图在你的输入文件(main.ts)的开头打破。 I've heard that we have this error message because the program is too short and terminates before the debugger can attach successfully. 我听说我们有这个错误消息,因为程序太短并且在调试器可以成功附加之前终止。 You have 2 solutions: 你有2个解决方案:

  • First, put your entry code inside a setTimeOut function with at least 1000 ms. 首先,将您的输入代码放入至少1000毫秒的setTimeOut函数中。 It should give enough of time to debugger to attach to your program. 它应该给调试器足够的时间来附加到你的程序。

  • The second solution is to set to your launch.json the options: "stopOnEntry" to "true" and set the runtimeArgs option to ["--inspect=5858", "--debug-brk"]. 第二种解决方案是将您的launch.json选项设置为:“stopOnEntry”为“true”,并将runtimeArgs选项设置为[“--inspect = 5858”,“ - debug-brk”]。

Like this: "configurations": [ { "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon", "runtimeArgs": [ "--inspect=5858", "--debug-brk" ], "stopOnEntry": true, "program": "${workspaceRoot}/src/server/main.ts", "restart": true, "port": 5858, "protocol": "inspector", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "outFiles": ["${workspaceRoot}/dist/**/*.js"], "sourceMaps": true } ] 像这样: "configurations": [ { "type": "node", "request": "launch", "name": "nodemon", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon", "runtimeArgs": [ "--inspect=5858", "--debug-brk" ], "stopOnEntry": true, "program": "${workspaceRoot}/src/server/main.ts", "restart": true, "port": 5858, "protocol": "inspector", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "outFiles": ["${workspaceRoot}/dist/**/*.js"], "sourceMaps": true } ]

It will break at the first line of your main.js and then, by pressing F5, you will be able to break on your own breakpoint in main.ts. 它将在main.js的第一行中断,然后按F5,您将能够在main.ts中断开自己的断点。 If you don't want, each time you run your program, to press F5 until it reaches your breakpoint, I suggest you to use the first solution (Embed your main.ts entry code inside a setTimeOut function with a least 1000 ms). 如果你不想要,每次运行你的程序时,按F5直到它到达你的断点,我建议你使用第一个解决方案(将你的main.ts条目代码嵌入setTimeOut函数中至少1000毫秒)。 I hope it will help you 我希望它会对你有所帮助

@Philoufelin, thanks for your effort. @Philoufelin,谢谢你的努力。 I have now tested them following your suggestions. 我现在按照你的建议测试它们。

... added to file tsconfig.json ...添加到文件tsconfig.json

"outDir": "./dist"

snapshot from file launch.json 来自文件launch.json的快照

"configurations": [
   {  
     "type": "node",
     "request": "launch",
     "name": "nodemon",
     "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/nodemon",
     "runtimeArgs": [ "--inspect=5858" ],
     "program": "${workspaceRoot}/src/server/main.ts",
     "restart": true,
     "port": 5858,
     "protocol": "inspector",
     "console": "integratedTerminal",
     "internalConsoleOptions": "neverOpen",
     "outFiles": ["${workspaceRoot}/dist/**/*.js"],
     "sourceMaps": true
   }
 ]

But it does not work. 但它不起作用。 After 10s vscode flashes the message ... 10秒后,vscode闪烁消息......
Cannot connect to runtime process, timeout after 10000 ms - (reason: Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:5858) 无法连接到运行时进程,10000毫秒后超时 - (原因:无法连接到目标:连接ECONNREFUSED 127.0.0.1:5858)

nodemon also prints out the following line on start: nodemon还会在开始时打印出以下行:
chrome-devtools://devtools/bundled/inspector.html?experiments=true&v8only=true&ws=127.0.0.1:5858/a0f8f52a-47ec-4ddb-9f03-4eb1c97ef8aa

I tried this link in chromium, attachment works, but debugger statements or breakpoints are ignored. 我在chrome,附件工作中尝试了这个链接,但忽略了调试器语句或断点。

I observed a further difference to normal debugging with vscode. 我观察到使用vscode进行正常调试的另一个区别。 Normal debugging starts in the DEBUG CONSOLE tab. 正常调试在DEBUG CONSOLE选项卡中启动。 Launching nodemon starts in the TERMINAL tab. 启动nodemon在TERMINAL选项卡中启动。

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

相关问题 可以将 Visual Studio Code 配置为使用 nodemon 启动吗 - Can Visual Studio Code be configured to launch with nodemon 用于带有Nodemon的Visual Studio的节点 - Node for Visual Studio with Nodemon 调试〜10秒后,Visual Studio代码nodemon ECONNREFUSED - Visual Studio Code nodemon ECONNREFUSED after ~10 s of debugging Visual Studio Code,调试节点 - 我怎样才能达到这个“未验证的断点”? - Visual Studio Code, Debugging Node - How can I hit this 'Unverified Breakpoint'? 更新 vscode-languageclient 后,我的 Visual Studio Code 扩展不再编译 - After updating vscode-languageclient, my Visual Studio Code extension does not compile any more 在 Visual Studio Code 中为 dockerized 节点进程设置了断点但尚未绑定 - Breakpoint set but not yet bound in Visual Studio Code for a dockerized node process Visual Studio Code 未绑定断点 Node JS React TypeScript - Visual Studio Code unbound breakpoint Node JS React TypeScript Visual Studio 代码断点在使用 TypeScript 的 Node.js 上不起作用 - Visual Studio code breakpoint not working on Node.js using TypeScript 使用 lerna 时看不到 nodemon 控制台更改和日志 - Can't see nodemon console changes and logs when using lerna 在Visual Studio Code中找不到节点可执行文件 - Node executable can't be found in Visual Studio Code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM