繁体   English   中英

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

[英]Debug in visual studio code is not working

启动配置

{
    // 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}"
        }
    ]
}

在 Visual Studio 代码中调试我的反应代码时出现以下错误。 实际上,我已经使用 node+react 创建了项目,并使用 Visual Studio 作为 IDE,并想调试我的代码。 我已经尝试了很多但无法成功调试我的代码。

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)

我通过在要调试的函数中添加以下代码来解决它:

debugger;

并开始调试。 快乐编码!!

要在没有 launch.json 的情况下在 vs 代码中开始调试,

转到文件→首选项→设置→扩展→节点调试→[选择]“开”

图像启用调试器

我遇到了同样的问题,结果提示在控制台中: Debugging with legacy protocol because Node.js v6.10.2 was detected

我使用以下步骤解决了它:

  • 关闭 VS 代码
  • 卸载节点
  • 使用NVM安装节点 v5
  • 删除项目中的node_modules文件夹
  • 重新打开 VS Code
  • 运行npm install

放置一个断点并重试。

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

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

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

我从 .net core 3.1 升级到 .net core 6 并且调试没有采用我的新控制器方法。 我必须将配置下的 launch.json 程序关键字更新到正确的位置。 我将 Debug 和 Controllers.dll 之间的值从 netcoreapp3.1 更改为 net6.0 在此处输入图片说明

暂无
暂无

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

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