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

8
我需要启动一个特定的.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

当我通过CMD执行第二个命令时,我可以使用chromedev工具调试器进行调试。但是当我需要使用VS Code编辑器进行调试时,我的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"
]

我一直在控制台上收到此消息:附加调试器,等待调试器断开连接,但执行没有启动。请问有人可以告诉我如何使用 VS Code 调试这个应用程序吗?

npx 希望作为第一个参数传入一个模块/二进制文件。因此,如果你已经将 jest 安装为一个模块,你可以运行 npx jest ...。我认为 npx app.js 没有意义。 - Marc
不确定这个是否仍然有效,WebdriverIO调试文档已经更新,并提供了一个示例VSCode配置 https://webdriver.io/docs/debugging.html#debugging-with-visual-studio-code-vscode这解决了你的问题吗? - Mike G.
1个回答

3
https://webdriver.io/docs/debugging提供如何在VS Code中运行的详细信息(感谢Mike的评论):
  1. Go to Run and Debug tab/blade (Ctrl + Shift + D)

  2. Create a launch.json file (e.g. type Node.js on environment bar) or click the cog at the top for other options

  3. .vscode/launch.json opens up or locate and open it (from project's root folder)

  4. Paste this in the configurations array, adjust according to your parameters/arguments and save the file:

     {
         "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"
         ]
     },
    
  5. Run the above by choosing this configuration (e.g. "run select spec") from the top left dropdown/select menu (or press F5 if already selected).


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接