Cannot run deno debugger on vscode - debugging

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)

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

Next JS Server Side Default Port for Debugging

I've been trying to debug my server side code in NextJS by marking a breakpoint. I am using VSCode to my development.
Initially, my launch.json was like this.
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
}
]
}
This works fine; however, it does not hit any server side code like getStaticProps, getStaticPaths and getServerSideProps.
I found this blog post that I believe can solve my problem. So I added a script to my package.json, and amend my launch.json. So now it looks like this
package.json
{
"scripts": {
"debug": "node --inspect-brk ./node_modules/next/dist/bin/next"
}
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}"
},
{
"type": "node",
"request": "launch",
"name": "Launch Next.js",
"runtimeExecutable": "npm",
"runtimeArgs": [
"run-script",
"debug"
],
"port": 3000
}
],
"compounds": [
{
"name": "Debug Next.js + Chrome",
"configurations": [
"Launch Next.js",
"Launch Chrome against localhost"
]
}
]
}
So when I try to run this, I got an error to my Launch Next.js configuration.
I believe this is because I am pointing to an incorrect port. I tried to search what is the default port for server side part of NextJS. But I cannot find one.
I have same problem with setting breakpoint on API, so I took a few hours to figue out what's the real problem. Finally I found the issue:
Because when you run a Nextjs app, Node will first run next script, then next script will spawn a child process which is your own code. Nextjs also automatically set NODE_OPTIONS=--inspect when you use dev mode, but it use different port number and the number changes automatically. The KEY POINT is: The Next script and the child process will have different debugging port number. , That is the reason that you sometimes can't set breakpoints.
There are some senarios:
If you start your server manually in VSCODE terminal by type "npm run dev", VSCODE will
automatically find the debugging ports and you will be fine.
If you start your server outside of VSCODE from a terminal, and then use
attach, VSCODE will only attach one port, usaully only attached to
Nextjs script. That's why you can't set breakpoint in you own code.
If you use launch method to start server in launch.json. Then same
problem will happened like No.2, You can't set your breakpoint.
There is a simple way to solve the problem: Either start server from VSCODE internal terminal or in launch.json, add:
"autoAttachChildProcesses": true,
then you can start debugging by hit F5 and everything going well.
{
"name": "Next.js: debug full stack",
"type": "node-terminal",
"request": "launch",
"command": "npm run dev",
"serverReadyAction": {
"pattern": "started server on .+, url: (https?://.+)",
"uriFormat": "%s",
"action": "debugWithChrome"
},
"autoAttachChildProcesses": true,
}

Could not find the task 'tsc: build - tsconfig.json'

Hello I am following this tutorial
https://code.visualstudio.com/docs/typescript/typescript-tutorial
to debug typescript but I have encountered error as shown in the screenshot.
If I choose debug anyway, the debugger works but I cant set any breakpoint. I suspect it has something to do with failing to set up the task file.
Any advise guys?
I had a similar problem. In my case, the tsconfig.json file was not in the main folder, but in a subfolder. In my case, the working configuration looked like this
{
"type": "node",
"request": "launch",
"name": "Launch server",
"program": "${workspaceFolder}/server/index.ts",
"preLaunchTask": "tsc: build - server/tsconfig.json",
"outFiles": ["${workspaceFolder}/out/**/*.js"]
}
Task tsc: build - tsconfig.json by default comes from VSCode when it detects the existence of tsconfig.json. Based on your screenshot, I can tell that you already have the file. So, it is odd if it can't be detected.
Please make sure the file content of tsconfig.json is valid.
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"outDir": "out",
"sourceMap": true
}
}
Also to check whether the tasks are exist, you can choose menu Terminal -> Run Build Task or press Shift + Command + B on MacOS. If correct, you can see two tasks available there as the image below.
Otherwise, there must be something wrong with the steps. Perhaps, there is an extra space in preLaunchTask. For reference, I also copy paste my launch.json here.
{
// 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",
"name": "Launch Program",
"program": "${workspaceFolder}/helloworld.ts",
"preLaunchTask": "tsc: build - tsconfig.json",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
]
}
]
}
For other language users, the tsc: build command maybe be another command, such as tsc: 构建 in Chinese.
my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}/index.ts",
"preLaunchTask": "tsc: 构建 - tsconfig.json",
"outFiles": [
"${workspaceFolder}/out/**/*.js"
]
}
]
}
When you Ctrl+Shift+B terminal will run Run Build Task.. You'll see in the terminal
">Executing task: tsc -p c:....
Terminal will be reused by tasks, press any key to close it."
Then after that double click a ts file and press F5 you will have to select at which environment do you want your ts file to run and then you will see the output in the debug console.
because it does not find path of tsconfig file....
see your folder structure whether the structure contains multiple same folder with same name...so y debugger confused to find path....so make sure the devlopement folder which you work on has proper path with unique name no same name with its parent folder and contains tsconfig files...
This happens also if the Extension Host crashed. This prevents the task engine from finding the requested task. Usually, you should see a message in the toaster where you can immediately restart the Extension Host. After that the debugger and tasks work.
For Ubuntu Linux 20.04 LTS (but may well be the same on other OS's) what got preLaunchTask working for me, was using both a local tasks.json and launch.json
So my folder structure (pre-build) is:
.vscode/launch.json
.vscode/tasks.json
dist
src/index.ts
package.json
tsconfig.json
My launch.json contains:
{
"configurations": [
{
"type": "node",
"request": "launch",
"name": "TS preLaunchTask-build",
"program": "${file}",
"preLaunchTask": "tsc: build",
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"skipFiles": [
"<node_internals>/**", "node_modules",
]
},
]
}
My tasks.json contains:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"command": "echo hello yes working!",
"problemMatcher": [],
"label": "myTask"
},
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"problemMatcher": ["$tsc"],
"group": "build",
"label": "tsc: build"
},
]
}
And my tsconfig.json contains:
{
"compilerOptions": {
"outDir": "./dist",
"sourceMap": true,
"target": "es5",
"module": "commonjs"
},
"include": [
"src/**/*"
]
}
Usage: whilst within the index.ts just hit F5 with a breakpoint set
I have also included another task, "myTask" you can change the preLaunchTask line in your launch.json to: "preLaunchTask": "myTask", (where it will output some text to console to verify preLaunchTask is now working)
That way, if you still have issues, you can see if the issue is in your tsconfig setup, or if it's a preTaskLaunch setup issue.
(I would have thought it should have resolved this itself, but apparently not at the current time of writing anyway - but does force the advantage (for me) of committing debug config to the repo on project basis rather than global config)
Be sure to check the exact structure/spelling of Task by pressing Ctrl+Shift+B (on Windows) and Cmd+Shift+B(on Mac).
In my case, it was tsc: build - projectName/tsconfig.json

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

Visual Studio Code - Debugging

I downloaded the Visual Studio Code, but I don't know how to configure the debugger.
I am learning programming and i don't know how to configure it?
someone help me with this problem?
This is what you need to configure.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
You need to be more specific with your question.
What kind of code are you debugging?
Right now Visual Studio Code has debugging support for Node.js (JavaScript and TypeScript) on all platforms, experimental support for mono (C# and F#) on OS X and Linux, and soon ASP.NET 5.
If you are using one of those, you should be able to start using debugging features.
For more information, here is a direct link to the official debugging documentation: https://code.visualstudio.com/Docs/debugging
If you are coding with php you can follow these step
You can copy and paste code:
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]

Resources