Hi does anyone have by …

2 minute read

Hi! does anyone have by any chance an example (or a link to the docs) where I can see how to configure vscode tasks to run/debug nx node apps?

Responses:

this works for me (launch.json) { "type": "node", "name": "nx affected:tests", "request": "launch", "args": [ "affected:test", "--base=origin/develop", "--passWithNoTests" ], "cwd": "${workspaceFolder}", "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "program": "${workspaceFolder}/node_modules/.bin/nx" }

At least VS code you dont need config. you can open terminal in debug mode and just you your nom script normally :slightly_smiling_face:

does this task let’s you connect to the debug port?

that will allow you run affected tests in vscode

yeah, i usually trigger them through the terminal. I’m more interested in using the vscode debugger :sweat_smile:

you should be able to modify it to open up inspector tho

a little more context, I used to have this task: {     "name": "Debug API",   "type": "node",   "request": "attach",   "port": 7777     }, Where port was the default 7777 in @nrwl/node:build

I would then start the process with ng serve api and then launch the task and it would connect to the debug port

Just use the debug terminal. No more need for the config :slightly_smiling_face: save yourself time

After upgrading to the latest version of nx somehow vscode throws a timeout when trying to attach

what is the debug terminal?

you mean the DEBUG CONSOLE window in vscode?

No they have a new debug terminal

oh, didn’t know that. how do I open it?

oh, weird. it doesn’t show me the option. but i’ll try to find it :slightly_smiling_face:

i guess it doesn’t show it because i already have a launch.json

yea you may have to remove it

That or its a new feature on the insider version only. But its useful and dont need the config now

yea i dont have that button either

and no launch.json

mmm, then I guess it’s an insiders feature, yeah

Insider version then :slightly_smiling_face: You will have to wait for it to come out. But i wont use config anymore. There very little need

Sorry for confusing. Just thought i point it out as most wont known it existed if they have a config

thx anyway

coming back to the launch.json configuration, , I tried to use it in a similar way and this is what I ended up with { "type": "node", "name": "Debug API 2", "request": "launch", "runtimeExecutable": "npm", "runtimeArgs": ["run-script", "start:api"], "cwd": "${workspaceFolder}", "skipFiles": ["<node_internals>/**"], "port": 7777, "preLaunchTask": "npm:tsoa:all" },

I’m having trouble with it though because it still tells me Cannot connect to runtime process, timeout 10000 ms I’m pretty sure the problem is that it needs to build and THEN attach, any ideas on how could I tackle this configuration? It may be a common use case for node/typescript projects. I’ll try to research a bit online

node inspector needs to be turned on, its off by default. try adding "debug" to your runtimeArgs

https://code.visualstudio.com/docs/nodejs/nodejs-debugging

If you used the attach debugger before, you might have to change the port in the project builder to 7777

default is 0 now

oh sorry, the execute has the port

https://nx.dev/angular/plugins_node_builders/execute#port

Updated: