无法在 Visual Studio 代码中为“npx”启动的应用程序启动调试

Ton*_*ost 7 debugging node.js webdriver-io visual-studio-code

我需要以这种方式启动一个特定的 .js 文件来执行:

  1. npx app.js launch.conf.js //用于执行脚本

  2. npx app.js debug.conf.js //用于调试脚本

在我的 debug.conf.js 中包含

const config = {
  debug: true,
  execArgv: ['--inspect-brk'],
  maxInstances: 1,
  cucumberOpts: {
    timeout: 30 * 1000 * 4,
  },
};
exports.config =config
Run Code Online (Sandbox Code Playgroud)

, 当我通过 CMD 执行第二个命令时,我可以使用 chromedev 工具调试器进行调试。但是当我需要使用 VS 代码编辑器进行调试时:这存在于我的 launch.json 文件中:

"type": "node",
"name": "manager",
"request": "launch",
"protocol": "auto",
//  "port": 5859,
"program": "${workspaceRoot}\\node_modules\\cdem\\bin\\app",
"execArgv": ["--inspect-brk"],
"args": [
    "run wdio.debug.conf.js"
]
Run Code Online (Sandbox Code Playgroud)

我一直将控制台操作设为:附加调试器,等待调试器断开连接并且未启动执行。

有人可以让我如何使用 VS Code 调试这个应用程序吗?

CPH*_*hon 3

https://webdriver.io/docs/debugging提供了有关如何在 VS code 中运行的详细信息(谢谢 Mike(评论)):

  1. 转到“运行和调试”选项卡/刀片 ( Ctrl++ )ShiftD

  2. 创建一个 launch.json 文件(例如,在环境栏上键入Node.js)或单击顶部的齿轮以获取其他选项

  3. .vscode/launch.json打开或找到并打开它(从项目的根文件夹)

  4. 将其粘贴到配置数组中,根据您的参数/参数进行调整并保存文件:

     {
         "name": "run select spec",
         "type": "node",
         "request": "launch",
         // To run all spec files remove "--spec", "${file}" from below
         "args": ["wdio.conf.js", "--spec", "${file}"],
         "cwd": "${workspaceFolder}",
         "autoAttachChildProcesses": true,
         "program": "${workspaceRoot}/node_modules/@wdio/cli/bin/wdio.js",
         "console": "integratedTerminal",
         "skipFiles": [
             "${workspaceFolder}/node_modules/**/*.js",
             "${workspaceFolder}/lib/**/*.js",
             "<node_internals>/**/*.js"
         ]
     },
    
    Run Code Online (Sandbox Code Playgroud)
  5. 通过从左上角的下拉/选择菜单中选择此配置(例如“运行选择规范”)(或者F5如果已选择,请按)来运行上述命令。