SAP-archive/cloud-cap-nodejs-codejam

Unable to invoke Debugger

scottdillon1 opened this issue · 11 comments

As part of the exercises, we are asked to run the VS Code debugger but when I try to do that, I receive the following error.

VSDebug

Hi @scottdillon1,
I get the same error. Did you solve it?

Thanks in advance,
Marc

@scottdillon1 @socenmarc
I had the same problem and found out this could be caused by having spaces in your node path installation on Windows.
e.g. C:\Program Files\nodejs

I updated my nodejs to the latest version + installed it into another path (without spaces) and from now on I can use debugger as in the exercises.

Hi @DusanSacha, thanks for answering.

Another option:

  • Create a new file cds.js in the .vscode directory
  • In the new file cds.js, add the following code:

// used in launch.json to refer to an installed cds via an absolute path
const cds = require('@sap/cds')
cds.exec()

  • In .vscode directory, replace launch.json code with:

{
// 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": [
{
"name": "cds run",
"type": "node",
"request": "launch",
"program": "${workspaceFolder}/.vscode/cds",
"args": [
"run"
],
"skipFiles": [
"<node_internals>//*.js",
"
/cds-reflect/lib/index.js",
"/cds/lib/index.js",
"
/.vscode/cds.js"
],
"autoAttachChildProcesses": true,
"console": "integratedTerminal"
}
]
}

That works for me.

Regards,
Marc

chgeo commented

For new projects, this will be fixed by @sap/cds 3.20.0 tomorrow.

Is there any example/ guidance how to setup the launch.json for debug? I am facing the same issue.

I just created a new project with cds 3.20.1 and this is the launch.json I got generated:

{
  // 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": [
    {
      "name": "cds run",
      "type": "node",
      "request": "launch",
      "program": "${workspaceFolder}/.vscode/cds",
      "args": [ "run", "--with-mocks", "--in-memory?" ],
      "skipFiles": [ "<node_internals>/**" ],
      "console": "integratedTerminal",
      "autoAttachChildProcesses": true
    }
  ]
}

and cds.js in the same directory:

// used in launch.json to refer to an installed cds via an absolute path

const cds = require('@sap/cds');
cds.exec();

I hope this helps

In case it helps, following worked for me

In launch.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": [
{
"name": "cds run",
"request": "launch",
"type": "node", "runtimeExecutable": "npx","runtimeArgs": [ "-n" ],
"args": [ "--","cds","run", "--in-memory" ], // the leading "--" arg ensures it works with as well as without debugging
"cwd": "${workspaceFolder}/packages/bookstore",
"console": "integratedTerminal",
"skipFiles": [ "<node_internals>/**" ]
}
]
}

Great!

I'll close this issue now, as it seems to be resolved. Please reopen if needed.

Hi all, still having issues with the new debug launch.json. I can run "cds run" with no problems in a terminal but when I run these on VSCode Debuger that happens:
image

I really need help on that.

chgeo commented

This looks like you run an old Node.js version. Should be version 10 minimum.
Check with node --version.