How can I debug my typegraphql resolvers in VS Code? - apollo-server

so I got my typeorm, typegraphql, apollo-server-express, typescript endpoint up and running with resolvers, mutations and all that stuff.
Having a c# background I sometimes want to debug my endpoint when making requests to the playground to figure out what I'm doing wrong. I haven't found a setup in which vscode allows me to do that, also google wasn't much of a help.
Is it possible what i'm trying to achieve? Thanks

I made it using the following launch.json, maybe this helps someone else
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register"],
"args": ["src/index.ts", "--transpile-only", "hello"],
"cwd": "${workspaceRoot}",
"internalConsoleOptions": "openOnSessionStart",
"skipFiles": ["<node_internals>/**", "node_modules/**"]
}
]
}

Related

Unable to debug a TypeScript testing framework using Visual Studio Code

I am not able to get debugging working on VSCode for a testing framework using WebdriverIO . Only this message is displayed: - Waiting for the debugger to disconnect.
However, I am able to get debugging up and running for a TS code one time. If I am starting my machine once, and then again, it is giving same issue as - Waiting for the debugger to disconnect.
Below is the launch.json file:
{
// 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": [{
"type": "node",
"request": "launch",
"skipFiles": [
"<node_internals>/**"
],
"outputCapture": "std",
"name": "Launch Program",
"program": "${workspaceRoot}/node_modules/#wdio/cli/bin/wdio.js",
"args": ["${workspaceRoot}/build/main/config/wdio.conf.js"],
"preLaunchTask": null,
"sourceMaps": true,
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"resolveSourceMapLocations": [ //code to avoid 'Could not read sourcemaps' issues
"${workspaceFolder}/**",
"!**/node_modules/**"
]
}]
}
Console-log stack-trace:
C:\Program Files\nodejs\node.exe .\node_modules#wdio\cli\bin\wdio.js
C:\Automation\angular_ui-auto-framework/build/main/config/wdio.conf.js
Debugger attached.   Execution of 1 workers started at
2022-12-21T15:25:32.199Z   [2022-12-21 20:55:32:902] - DONE - File
'c:\Automation\angular_ui-auto-framework\src\osr_ui-automation\Results\testReport.json'
is deleted successfully    Waiting for the debugger to disconnect...
I have faced similar problems with latest version of the vscode. I had to downgrade to nodejs 16lts and downgrade vscode to 1.57 and using below launch.json working fine so far.
{
"name": "Start Spec",
"type": "node",
"request": "launch",
"args": ["wdio.conf.js", "--spec", "${file}"],
"cwd": "${workspaceFolder}",
"autoAttachChildProcesses": true,
"program": "${workspaceRoot}/node_modules/#wdio/cli/bin/wdio.js",
"console": "integratedTerminal"
}

Cannot run deno debugger on vscode

I am a reccent deno user. Been using node for a long time, switched to deno and am very happy with it. It's really good
However, I have an issue.
Whenever I try to debug a deno file, the vscode debugger starts running for like half a second and then stops, and nothing happens.
It doesnt freeze or anything, it just starts for a moment and stops.
I am using this as launch configuration
{
"version": "0.2.0",
"configurations": [
{
"name": "Deno1",
"type": "node",
"request": "launch",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"outputCapture": "std",
"runtimeArgs": ["run", "--inspect-brk", "-A", "${fileName}"],
"port": 9229,
}
]
}
I took it from this post
I should add that I was able to debug this file already, but one day it just started showing this issue i just described without (to my knowledge) any change on my part.
I am trying to debug this file
How can I fix this issue?
To make it work you need to add a "program" field to launch.json and move the path of the file there, which is briefly mentioned in this answer from the post you linked to. But also you need to change "port" to "attachSimplePort":
{
"version": "0.2.0",
"configurations": [
{
"request": "launch",
"name": "Launch Program",
"type": "node",
"program": "${workspaceFolder}/tests/grammar.test.ts",
"cwd": "${workspaceFolder}",
"runtimeExecutable": "deno",
"runtimeArgs": [
"run",
"--inspect-brk",
"--allow-all"
],
"attachSimplePort": 9229,
"outputCapture": "std",
}
]
}
To debug another part of the application just change the path in program, for example to an entrypoint file like main.ts. With --inspect-brk the debugger will first break at the first line of the program and then you can for example continue to a breakpoint with F5 or the continue button in the debugger panel.
(Deno v1.14)

Debugging strapi in Visual Studio Code

I'm trying to debug my strapi project (3.0.0 beta 16.6) in VS Code.
My launch.json:
{
"type": "node",
"request": "attach",
"name": "Attach to strapi",
"port": 9229
}
My package.json:
"scripts": {
"debug": "node --inspect=127.0.0.1:9229 ./node_modules/strapi/bin/strapi.js develop"
}
Debugger attaches to the process, but all my breakpoints become unverified (appear black, not red). What's wrong with my configs?
this answer come from the following strapi/strapi issue:
I have come up with next solution:
having next script in server.js file (my custom one):
const strapi = require('strapi');
strapi({ dir: process.cwd(), autoReload: true }).start();
I'm using nodemon by next command: nodemon --inspect=0.0.0.0:9228 server.js
Now I can attach to 9228 by debugger.
Just to add to #alxnkt comment.
I have encountered the same and solved it by changing the launch.json to port 9230
{
"type": "node",
"request": "attach",
"name": "Attach to strapi",
"port": 9230
}
while keeping the port on package.json as 9229
"debug": "node --inspect=127.0.0.1:9229 ./node_modules/strapi/bin/strapi.js develop"
There are somehow 2 processes running when calling the Strapi develop command (possibly the admin panel and its core server), the process we have to monitor becomes port 9230 instead.
Add VS configuration "NODE: launch via npm" in .vscode/launch.json "configurations" property and run
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"develop"
],
"port": 9229,
"skipFiles": [
"<node_internals>/**"
],
"console": "integratedTerminal"
}
This worked for me using Strapi v4
{
"version": "0.2.0",
"configurations": [
{
"name": "STRAPI Debug",
"type": "node",
"request": "launch",
"cwd": "${workspaceRoot}",
"runtimeExecutable": "node",
"runtimeVersion":"14.19.0",
"runtimeArgs": ["--lazy"],
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceRoot}/node_modules/#strapi/strapi/bin/strapi.js",
"args": [
"develop"
],
"protocol": "inspector",
"env": {
"NODE_ENV": "development"
},
"autoAttachChildProcesses": true,
"console": "integratedTerminal"
},
]
}
The problem has been solved by setting port number to 9203:
{
"type": "node",
"request": "attach",
"name": "Attach to strapi",
"port": 9229
}
But I have no idea about HOW it works...
I just launched it via NPM, here is my launch.json (in .vscode folder)
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch via NPM",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"develop"
],
"port": 9229,
"skipFiles": [
"<node_internals>/**"
],
"console": "integratedTerminal"
}
]
}
You can also use NODE_OPTIONS:
NODE_OPTIONS='--inspect' yarn strapi develop
You'll get:
$ NODE_OPTIONS="--inspect" yarn strapi develop
Debugger listening on ws://127.0.0.1:9229/8564942a-6476-443a-9f64-87fa6d0055b7
For help, see: https://nodejs.org/en/docs/inspector
yarn run v1.22.5
$ strapi develop
Starting inspector on 127.0.0.1:9229 failed: address already in use
Debugger listening on ws://127.0.0.1:9230/7da840dd-cb89-493f-8ce0-e11530efdfbb
For help, see: https://nodejs.org/en/docs/inspector
Now you can use Debug: Attach to Node Process to attach to port 9230.
For strapi v4 you will have to add "sourceMap": true to compilerOptions of tsconfig.json file.

Debugging in Visual Studio Code?

I followed the instructions for debugging in VSCode as per
https://github.com/Microsoft/vscode-react-native
I attached my Nexus 6P with USB cable with my MBP2015 and enabled Developer Options and USB Debugging but when I select Debug Android in VSC, I get this
[Error] "Could not debug. Android project not found."
I have attached picture of this, too.
If I want to debug on IOS simulator, I select Debug IOS in VSC but then I get this and simulator is not started
[vscode-react-native] Prewarming bundle cache. This may take a while ...
[vscode-react-native] Building and running application.
[vscode-react-native] Executing command: react-native run-ios --simulator
Scanning 772 folders for symlinks in /Users/me/reactnativework/my-app/node_modules (4ms)
ENOENT: no such file or directory, uv_chdir
[Error] "Could not debug. Error while executing command 'react-native run-ios --simulator': Error while executing command 'react-native run-ios --simulator'"
I have seen few posts here about similar problem but none are answered or are not same issue like I have.
How do I debug a simplest possible React Native app using break points so I can follow how code executes in Visual Studio Code?
Here is my 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": "Debug Android",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"name": "Debug iOS",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"name": "Attach to packager",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "attach",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
{
"name": "Debug in Exponent",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "launch",
"platform": "exponent",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
}
]
}
Follow these steps
Install Extension React-native Full Pack
Create Launch.json
Select Debug iOS or Android .Add Breakpoint and enjoy.
Note: Please make sure you enable Debug JS Remotely
Now grab a coffee and enjoy!
There are several ways to enable break point debugging using vs code
Run packager and debugger using vs code :Debug Android/ Debug iOS
Using exponent
Attach to packager
As far as my experience, the most stable debugging in vs code is by using the third option, Attach to packager.
To use this, you can start an external packager (from command line i.e) and attach the debugger to that packager port.
{
"name": "Attach to packager",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "attach",
"port": 19002, // change this with your port
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react"
},
The other 2 options always causing multi instance packager and causing packager error, end up with spending time killing the port. At least for me, using attach to packager is a lot more comfortable.
If you create the app by using exponent, then you won't be able to run the Debug Android/Debug iOS, the only option is by using the Debug in exponent or you still can use attach to packager with same method as before.
There is a way to do it with just one click of a button. Debugger will attach to packager after the simulator is started and packager is already running.
Configure launch.json file like this:
"configurations": [
{
"name": "Debug",
"program": "${workspaceRoot}/.vscode/launchReactNative.js",
"type": "reactnative",
"request": "attach",
"sourceMaps": true,
"outDir": "${workspaceRoot}/.vscode/.react",
"port": "8081",
"address": "localhost",
"preLaunchTask": "npm: debug:dev"
},
]
And in package.json you just need to add new script:
"scripts": {
"debug:dev": "react-native run-ios --scheme 'My project scheme' --configuration 'Debug' --simulator 'iPhone 8'",
Another way can be to use React Native Tools extension provided by Microsoft on VS code to debug react native app within VS Code itself rather than Chrome.
Check all instructions in detail in my answer here.
{ "version": "0.2.0", "configurations": [
{
"name": "Debug Android",
"type": "reactnative",
"request": "launch",
"platform": "android",
"sourceMaps": true,
"cwd": "${workspaceFolder}"
},
{
"name": "Debug iOS",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"target": "iPhone 11 Pro Max",
"sourceMaps": true,
"cwd": "${workspaceFolder}"
},
{
"name": "Debug Attach",
"type": "reactnative",
"request": "attach",
// "platform": "ios",
// "target": "iPhone 8",
"sourceMaps": true,
"cwd": "${workspaceFolder}"
},
{
"name": "Debug Device iOS",
"type": "reactnative",
"request": "launch",
"platform": "ios",
"target": "device",
"runArguments": ["--device"],
"sourceMaps": true,
"cwd": "${workspaceFolder}"
}
]
}
Found out that using Chrome allows debugging, tracing, breakpoints, tried it, working good

Is it possible to debug go revel framework from Visual Studio Code?

I'm trying to debug a revel app with visual studio but I can't get it to work.
I've seen this question how to debug revel framework(golang) application in visual studio code(vscode) but no answers yet...
I've tried with this config:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "~/code/go/bin/revel",
"env": {},
"args": [],
"showLog": true
}
]
}
But I'm getting this error:
Failed to continue: "The program attribute must point to valid directory, .go file or executable."
I think it must be the rebel binary the one to be run here, but I don't know how to pass the app path, should it go in "args"?
Yes it's possible.
Suppose that the GOPATH is C:\Work\golang
Revel project name is myapp, thus the location of the project (workspace) will be C:\Work\golang\src\myapp.
Make some changes to the controllers etc...
Run the application with revel run myapp, then press CTRL+C to exit. This step is necessary to generate corresponding go files. The generated file, i.e. the main package will be available under ${workspaceRoot}/app/tmp/main.go
Configure launch.json as follows:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"env": {},
"showLog": true,
"program": "${workspaceRoot}/app/tmp/",
"args": ["-importPath", "myapp", "-srcPath", "c:\\work\\golang\\src", "-runMode", "dev"]
}
]
}
The important parts are program and args parameters, while the other parameters are unmodified.
Set breakpoint and start the delve debugger...
EDIT:
Setting args parameter to ["-importPath", "myapp", "-srcPath", "${workspaceRoot}/..", "-runMode", "dev"] also work, and I think this should work in other platforms (Mac, Linux) too.
The error message is related to delve issue. See https://github.com/Microsoft/vscode-go/issues/986

Resources