Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to launch Debugging for a "npx" launched App in visual studio code

I need to launch a particular .js file for execution, in this way:

  1. npx app.js launch.conf.js //for execution of scripts

  2. npx app.js debug.conf.js //for debugging the scripts

In my debug.conf.js contains

const config = {
  debug: true,
  execArgv: ['--inspect-brk'],
  maxInstances: 1,
  cucumberOpts: {
    timeout: 30 * 1000 * 4,
  },
};
exports.config =config

, When I Execute the 2nd command via CMD I'm able to debug using chromedev Tools debugger. but when I need to debug using the VS code Editor:this is present in my launch.json file:

"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"
]

I keep getting the console op as: debugger attached, waiting for debugger to disconnect and the execution is not launched.

Can someone let me how to debug this app using VS Code?

like image 568
Tony Frost Avatar asked Jun 12 '18 16:06

Tony Frost


People also ask

Why is NPX not working in Visual Studio Code?

The term 'npx' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

How to debug NPX command in chrome?

You can find the answer here. you can debug an npx command providing the --node-arg=--inspect command line argument: Then in Chrome and you will find a NodeJs debugger button at the top of the Developer Tools panel:

How to debug create-react-app in NPX?

Search the file you need to debug (either in the tree view or using the quick search Cmd/Ctrl-O feature) and place a breakpoint in the Developer Tools editor. Then restart the npx command and start troubleshooting the create-react-app module.

Why can't I run NPX on my Machine?

It means that your machine can't execute npx command for some reason. You have an old version of the NPM that doesn't contain npx at all. You can check this using npm -v command Paths are not set up correctly (It looks like you are using Windows machine).

How do I launch a VSCode project with Node JS?

Create a launch.json file (e.g. type Node.js on environment bar) or click the cog at the top for other options .vscode/launch.json opens up or locate and open it (from project's root folder) Paste this in the configurations array, adjust according to your parameters/arguments and save the file:


1 Answers

https://webdriver.io/docs/debugging provides details on how to run in VS code (thank you Mike (comment)):

  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).

like image 80
CPHPython Avatar answered Oct 18 '22 03:10

CPHPython