Error while debugging in VS Code? - visual-studio-code

When I start debugging in Visual Studio Code it gives me error as
Attribute Program does not exist('Path')
This is my launch.json file code:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}\\serve",
"outFiles": [
"${workspaceFolder}/**/*.js"
]
}
]
}
I have visited some of links about the same problem but couldn't find any solution? Where am I doing wrong?

Related

How to configure launch.json for NextJs and Typesctipt

I am trying to create a launch.json file for the following repo:
https://github.com/zakariamofaddel/shopify-nextjs-template
I have tried both the default VS Code node template and the NextJs launch file.
VS code default Node generated .vscode/launch.json file
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\server\\index.ts"
}
]
}
I am able to run yarn dev successfully and use console.log:
https://github.com/zakariamofaddel/shopify-nextjs-template/blob/38c700d8706818aa12d892b3f1193a969919e003/package.json#L9
I found the solution after adding the TypeScript Debugger extension in VS code.
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug Localhost",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}\\server\\server.ts"
],
"runtimeArgs": [
"-r",
"ts-node/register/transpile-only"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"env": {
"NODE_ENV": "development"
}
}
]
}

Preload module in VSCode Launch debug

I'm trying to configure my VSCode launch.json for my node app. My node command for starting the app uses the -r flag to preload a module (dotenv/config). How do I configure that in my launch.json? I can't figure it out.
My run command:
node -r dotenv/config server.js
My launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-node",
"request": "launch",
"name": "My Launch",
"skipFiles": ["<node_internals>/**"],
"program": "${workspaceRoot}\\myapp\\src\\server.js",
"env": {
"MY_CONFIG_PATH": ".env"
}
}
]
}
I am also struggling with adding the preLoadedModules in my launch.json, but if you are just wanting to load your environment file you can add "envFile":"${workspaceFolder}/.env" to your launch.json and your app should run.
Example below:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\dist\\index.js",
"preLaunchTask": "tsc: build - tsconfig.json",
"envFile": "${workspaceFolder}/.env",
"outFiles": [
"${workspaceFolder}/dist/**/*.js"
]
}
]
}

Debug current open Flutter file in VSCode

I am writing a Flutter tutorial project in VS Code with multiple main() functions.
For example:
main.dart //Contains a main() function
step1.dart //Contains a main() function
step2.dart //Contains a main() function
If I have step1.dart open, then pressing F5 runs main.dart and not step1.dart in debug mode.
I can hover the mouse over the main() function in step1.dart, and then select 'debug' from the context menu. This works as expected and runs step1.dart in debug. However, there is no associated shortcut.
What can I press to run the active open file in debug mode, not main.dart?
As long as I have experience of having multiple flutter projects on a workspace (not too good feedback at all), the key is to set the pre-build process configuration file .vscode/launch.json, you can get more info on debugging#_launch-configurations.
When you create the file, it will look something like:
{
"version": "0.2.0",
"configurations": [
{
"name": "Flutter",
"request": "launch",
"type": "dart",
}
]
}
Then add "program": "lib/your-entry-point.dart":
{
"version": "0.2.0",
"configurations": [
{
"name": "main",
"request": "launch",
"type": "dart",
"program": "lib/main.dart"
},{
"name": "step1",
"request": "launch",
"type": "dart",
"program": "lib/step1.dart"
},{
"name": "step2",
"request": "launch",
"type": "dart",
"program": "lib/step2.dart"
}
]
}
This will then create the following launch options.
I made this launch.json file in the .vscode folder.
Worked like a charm.
{
"version": "0.2.0",
"configurations": [
{
"name": "Dart: Current File",
"type": "dart",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}"
},
]
}
Here are the variables you can use in launch.json.
https://code.visualstudio.com/docs/editor/variables-reference

VS Code console.log() appears in developer tools instead of debug console

I've been working on a VS Code extension using the Hello World example generated by Yeoman (yo code). The console.log() message only shows up in the Developer Tools, but not in the Debug Console like all of the VS Code documentation suggests. Here is my launch.json (it is unchanged from what yo code generated:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}",
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/suite/index"
],
"outFiles": [
"${workspaceFolder}/out/test/**/*.js"
],
"preLaunchTask": "${defaultBuildTask}"
}
]
}
I've tried adding "console": "internalConsole", "debugOptions": ["RedirectOutput"], and "outputCapture": "std" as suggested in various other answers on Stack Overflow, but A) none of those work and B) they give an error in launch.json that Property <property> is not allowed.
I'm launching using F5 (run with debugging). Breakpoints do work, logpoints don't log anything to Debug Console either.
What am I missing?

Running two projects at once in Visual Studio Code

I develop web project. Server is node.js application written in TypeScript. Client also written in Typescript. I need two ability:
to compile different projects with different compiler options in different folders.
to debug both projects at the same time.
How can I do this?
See our documentation on multitarget debugging: https://code.visualstudio.com/Docs/editor/debugging#_multitarget-debugging
In your launch.json, just create a compounds section that contains the targets you want to debug
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Server",
"program": "${workspaceRoot}/server.js",
"cwd": "${workspaceRoot}"
},
{
"type": "node",
"request": "launch",
"name": "Client",
"program": "${workspaceRoot}/client.js",
"cwd": "${workspaceRoot}"
}
],
"compounds": [
{
"name": "Server/Client",
"configurations": ["Server", "Client"]
}
]
}