简体   繁体   English

在 Visual Studio 代码中调试不起作用

[英]Debug in visual studio code is not working

Launch Configuration启动配置

{
    // Use IntelliSense to learn about possible Node.js debug attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "port": 5858
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Launch Program",
            "program": "${workspaceRoot}/src/app.js",
            "cwd": "${workspaceRoot}"
        }
    ]
}

I am getting the following error while debugging my react code in visual studio code.在 Visual Studio 代码中调试我的反应代码时出现以下错误。 Actually I have created the project with node+react and use visual studio as IDE and want to debug my code.实际上,我已经使用 node+react 创建了项目,并使用 Visual Studio 作为 IDE,并想调试我的代码。 I have tried a lot but not able to success to debug my code.我已经尝试了很多但无法成功调试我的代码。

Debugging with legacy protocol because Node.js v6.10.2 was detected.Program path uses differently cased character as file on disk; this might result in breakpoints not being hit.
node --debug-brk=21730 --nolazy src\app.js 
    Debugger listening on [::]:21730
    e:\reactjs\reactFacebook\my-app\src\app.js:1
    (function (exports, require, module, __filename, __dirname) { import React, { Component } from 'react';
                                                                  ^^^^^^
    SyntaxError: Unexpected token import
        at createScript (vm.js:56:10)
        at Object.runInThisContext (vm.js:97:10)
        at Module._compile (module.js:542:28)
        at Object.Module._extensions..js (module.js:579:10)
        at Module.load (module.js:487:32)
        at tryModuleLoad (module.js:446:12)
        at Function.Module._load (module.js:438:3)
        at Timeout.Module.runMain [as _onTimeout] (module.js:604:10)
        at ontimeout (timers.js:380:14)
        at tryOnTimeout (timers.js:244:5)

I resolved it by adding below code inside the function which I want to debug:我通过在要调试的函数中添加以下代码来解决它:

debugger;

and debugging started.并开始调试。 Happy coding!!快乐编码!!

For start debugging in vs code without launch.json,要在没有 launch.json 的情况下在 vs 代码中开始调试,

Goto File → Preferences → Settings → Extensions → Node Debug →[select ] "ON"转到文件→首选项→设置→扩展→节点调试→[选择]“开”

Image-Enable debugger图像启用调试器

I had the same issue, turns out the clue was in the console: Debugging with legacy protocol because Node.js v6.10.2 was detected .我遇到了同样的问题,结果提示在控制台中: Debugging with legacy protocol because Node.js v6.10.2 was detected

I resolved it using the following steps:我使用以下步骤解决了它:

  • Shutdown VS Code关闭 VS 代码
  • Uninstall node卸载节点
  • Install node v5 using NVM使用NVM安装节点 v5
  • Delete node_modules folder in project删除项目中的node_modules文件夹
  • Re-open VS Code重新打开 VS Code
  • Run npm install运行npm install

Place a breakpoint and try again.放置一个断点并重试。

非常简单的解决方案是->只需卸载调试器并删除launch.json文件,然后重新安装调试器然后启动

对我来说,调试只能在 cwd 设置为

"cwd": "${workspaceRoot}/src"

I upgraded from .net core 3.1 to .net core 6 and debugging was not picking up my new controller methods.我从 .net core 3.1 升级到 .net core 6 并且调试没有采用我的新控制器方法。 I had to update my launch.json program keyword under configurations to the correct location.我必须将配置下的 launch.json 程序关键字更新到正确的位置。 I changed the value between Debug and Controllers.dll from netcoreapp3.1 to net6.0我将 Debug 和 Controllers.dll 之间的值从 netcoreapp3.1 更改为 net6.0 在此处输入图片说明

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

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