簡體   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