3

在此处输入图像描述

在其中一个更新突然停止工作后。我现在正在通过 Chrome 开发人员工具进行调试。

ng serve 运行良好,应用程序运行良好。

但是,我想再次使用 VSCode 进行调试。尝试了几种导致上述相同问题的配置。2.

{
"version": "0.2.0",
"configurations": [

  {
    "name": "ng serve",
    "type": "chrome",
    "request": "launch",
    "url": "http://localhost:4200/#",
    "webRoot": "${workspaceFolder}",
    "sourceMapPathOverrides": {
      "webpack:/./*": "${webRoot}/*",
      "webpack:/src/*": "${webRoot}/src/*",
      "webpack:/*": "*",
      "webpack:/./~/*": "${webRoot}/node_modules/*"
    }
  },
  {
    "name": "ng test",
    "type": "chrome",
    "request": "launch",
    "url": "http://localhost:9876/debug.html",
    "webRoot": "${workspaceFolder}"
  },
  {
    "name": "ng e2e",
    "type": "node",
    "request": "launch",
    "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
    "protocol": "inspector",
    "args": ["${workspaceFolder}/protractor.conf.js"]
  }
]

}

2.

// {
//    // Use IntelliSense to find out which attributes exist for C# debugging
//    // Use hover for the description of the existing attributes
//    // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
//    "version": "0.2.0",
//    "configurations": [  
//        {
//            "name": "Launch Chrome with ng serve",
//            "type": "chrome",
//            "request": "launch",
//            "url": "http://localhost:4200",
//            "webRoot": "${workspaceRoot}",
//            "sourceMapPathOverrides": {
//                "webRoot": "${workspaceRoot}",
//                "webpack:/*": "${workspaceRoot}/*"
//            }
//        },
//        {
//            "type": "chrome",
//            "request": "attach",
//            "name": "Attach to Chrome",
//            "port": 9222,
//            "webRoot": "${workspaceFolder}"
//        }

//     ,]
// }
{
  "version": "0.2.0",
  "configurations": [{
      "name": "Launch Chrome",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:4200",
      "webRoot": "${workspaceFolder}",
      "sourceMapPathOverrides": {
        "webRoot": "${workspaceRoot}",
        "webpack:/*": "${workspaceRoot}/*"
      }
    },
    {
      "name": "Attach Chrome",
      "type": "chrome",
      "request": "attach",
      "url": "http://localhost:4200",
      "port": 9222,
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (Test)",
      "type": "chrome",
      "request": "launch",
      "url": "http://localhost:9876/debug.html",
      "webRoot": "${workspaceFolder}"
    },
    {
      "name": "Launch Chrome (E2E)",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/node_modules/protractor/bin/protractor",
      "protocol": "inspector",
      "args": ["${workspaceFolder}/protractor.conf.js"]
    }
  ]
}

禁用除 Debugger for Chrome Visual Studio Team Services 之外的所有扩展

未发现端口 4200 正在使用中

netstat -a -n -o

我应该如何更改launch.json并通过VSCode恢复调试能力?

4

1 回答 1

4

当端口正在使用时会发生此问题9222,因为此端口是调试模式的默认端口,因此只需使用另一个任意数字端口作为启动类型,就像我的 launch.json 文件一样

启动.json

{
    // Use IntelliSense to learn about possible 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": "chrome",
        "request": "launch",
        "name": "Launch Chrome",
        "url": "http://localhost:4200",
        "webRoot": "${workspaceFolder}",
        "port": 4040
        },
        {
          "type": "chrome",
          "request": "attach",
          "name": "Attach to Angular",
          "port": 9222,
           "webRoot": "${workspaceFolder}"
        }
    ]
}

在撰写此答案之前,这被认为是一个错误,并将在未来的版本中修复。

快乐编码

于 2018-07-11T08:01:15.480 回答