I have an app that is written in NestJS that I have inherited. When I try to debug the app using nest start --debug I am having trouble hitting breakpoints.
The odd thing is, if I put a breakpoint in my main.ts file, it hits it just fine. It's once the project has loaded up all the controllers, modules and the like that I cannot hit the breakpoints in the various .ts files. If I load up one of the .js files from my dist folder, I can breakpoint them, but everytime I stop and restart, I have to delete the contents of my dist folder. If i don't I get a TS5055 error about not being able to overwrite files.
Here's the tsconfig.json I have:
{
"compilerOptions": {
"module": "commonjs",
"declaration": true,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"watch": true,
"allowJs": true,
"allowSyntheticDefaultImports": true,
"target": "es2017",
"sourceMap": true,
"outDir": "./dist",
"baseUrl": "./",
"incremental": false,
},
"exclude": ["apminsightdata", "devops", "node_modules"]
}
The apminsightdata is because of site24x7 integration and devops is where I keep documents and SQL for our other teams to run when deploying.
add this configuration in the 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": "Launch app",
"type": "node",
"request": "launch",
"args": [
"src/main.ts"
],
"runtimeArgs": [
"-r",
"ts-node/register",
"-r",
"tsconfig-paths/register"
],
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"internalConsoleOptions": "openOnSessionStart",
"env": {
"NODE_ENV": "local",
"NODE_PORT": "3000"
},
"sourceMaps": true,
"console": "internalConsole",
"outputCapture": "std"
}
]
}
no need to config luangch.json
Open Vscode, and enter CTRL+SHIFT+P, select Toggle auto attach, choose always
Click the code line you want to debug
npm run start
It will hit the line you want to debug
Related
I have a C++ project running in VS Code. The CMake file has been created. Opening VS Code then triggers the creation of the settings.json file under .vscode. I then create the launch.json file. Things work properly. Later, I somehow trigger the creation of another debug configuration (from the C/C++ Runner extension?). My setting.json file goes from:
{
"cmake.sourceDirectory": "${workspaceFolder}/hello-world"
}
to:
{
"cmake.sourceDirectory": "${workspaceFolder}/hello-world",
"C_Cpp_Runner.msvcBatchPath": "",
"C_Cpp_Runner.cCompilerPath": "gcc",
"C_Cpp_Runner.cppCompilerPath": "g++",
"C_Cpp_Runner.debuggerPath": "gdb",
"C_Cpp_Runner.cStandard": "",
"C_Cpp_Runner.cppStandard": "",
"C_Cpp_Runner.useMsvc": false,
"C_Cpp_Runner.warnings": [
"-Wall",
"-Wextra",
"-Wpedantic",
"-Wshadow",
"-Wformat=2",
"-Wconversion",
"-Wnull-dereference",
"-Wsign-conversion"
],
"C_Cpp_Runner.enableWarnings": true,
"C_Cpp_Runner.warningsAsError": false,
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
"**/.*",
"**/.*/**",
"**/.vscode",
"**/.vscode/**"
]
}
My launch.json file also has this extra section added:
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"externalConsole": false,
"cwd": "/home/machine01/dev-workspace/repo01/hello-world",
"program": "/home/machine01/dev-workspace/repo01/hello-world/build/Debug/outDebug",
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
This automatic settings creation is very convenient. How do I trigger this again? I have tried many things to no avail.
Sorry I NUB in VS code. I want to start my edited gnuplot file using VS Code. I have a launch.json
{
"workbench.colorTheme": "Default Dark+",
"workbench.editor.enablePreviewFromCodeNavigation": true,
"workbench.editor.enablePreviewFromQuickOpen": true,
"workbench.experimental.settingsProfiles.enabled": true,
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"files.associations": {
"*.plt": "gnuplot"
},
"launch": {
"configurations": [
{
"name": "Run Project",
"request": "launch",
"args" : [
"${file}"
],
"program": "gnuplot",
"console": "internalConsole"
}
]
},
}
But I get an error "You dont have an extension for gnuplot".
I do not need any exteension, I just want to start edited file in console by pressing F5. I.e. I want VSC run commnad like gnuplot.exe {currently edited file}.
Running Visual Studio Code 1.52.1.
I created a simple VS Code extension as described in this tutorial. Then I added a dependency as shown below. The problem is that this dependency does not seem to get deployed when debugging.
package.json
"dependencies": {
"#types/markdown-table": "^2.0.0"
}
And the actual import looks like this:
import * as table from 'markdown-table'
Then I hit F5 just as described in the linked tutorial. When my registered command is run, I get the following error message:
Activating extension 'undefined_publisher.hello-world' failed: Cannot
find module 'markdown-table'
For completeness, here is the generated tsconfig.json:
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "src",
"strict": true
},
"exclude": [
"node_modules",
".vscode-test"
]
}
Should be able to add a preLaunchTask.
For Example in .vscode/launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"preLaunchTask": "npm: build"
}
]
}
We have an angular application (angular 8), the code is set up on an Ubuntu vm.
and using Visual Studio Code + Remote Development Tool (Microsoft) for development.
While development is working fine I am facing issues while debugging the app.
launch.json configuration
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:4200/#",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"runtimeArgs": ["--disable-session-crashed-bubble"]
},
{
"type": "chrome",
"request": "attach",
"name": "Attach to Chrome",
"port": 9222,
"address": "localhost",
"webRoot": "${workspaceFolder}",
"sourceMaps": true
}
]
}
vscode command used for port forwarding : "Forward Port From Active Host"
angular.json config for dev env
{
"dev": {
"optimization": false,
"outputHashing": "all",
"sourceMap": true,
"extractCss": true,
"namedChunks": true,
"aot": true,
"extractLicenses": true,
"vendorChunk": true,
"buildOptimizer": false,
"fileReplacements": [
{
"replace": "ui/environments/environment.ts",
"with": "ui/environments/environment.ts"
}
]
}
}
with this I am able to connect to the remote from local, however, the "Attach to Chrome" is not able to find the files and producing errors like
Unable to open 'dashboard.man~de6ca691.77f46380879a4a0699b4.js': Unable to read file (Error: File not found
(vscode-remote://ssh-remote+angular_serve/kite/angular_proj/dashboard/dashboard.man~de6ca691.77f46380879a4a0699b4.js)).
Is remote debugging like this is possible?
Am I missing any configurations?
To debug angular code follow these steps:-
Option 1 Using VS-code
https://scotch.io/tutorials/debugging-angular-cli-applications-in-visual-studio-code
OR
Option 2 You can directly use the chrome.
ctrl+shift+I and go to the source tab
ctrl+p you will get the list of files. choose your file for ex.
app.component.ts
Now you can see your code and use the sidebar you have line numbers
to select debug points.
Is it possible to invoke more than one pre-launch task using VS Code?
I try to restore packages then build then run but I can only get to configure build.
My launch.json:
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/src/myProject/bin/Debug/netcoreapp1.0/myProject.dll",
"args": [],
"cwd": "${workspaceRoot}/src/myProject",
"stopAtEntry": false,
"externalConsole": false
},
My tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"./**/project.json"
],
"isBuildCommand": true,
"showOutput": "always",
"problemMatcher": "$msCompile"
}
]
}
so I tried to specify the dotnet restore command however it does not work.
I know this is long over due. However, I think I figured out the solution. Steps I did.
Create a workspace to include all the projects in the workspace.
Go to Run and Debug, and click on "Add Config (workspace)
the format is the following:
{
"folders": [
{
"path": "project1"
},
{
"path": "project2"
},
],
"launch": {
"version": "0.2.0",
"compounds": [{
"name": "Chain Stars",
"configurations": [
"ConfigurationName1",
"ConfigurationName2",
]
}]
}
}
ConfigurationName1, and ConfigurationName2 is the profile name you would like to put them in sequence to launch your website.
4. Save the profile. In this case. "Chain Stars" is going to show up in the profile name for you to run it. Let me know if you have any questions.