VS code extension dependencies not being deployed when debugging? - visual-studio-code

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

Related

How to restart/reload VS Code host window on extension source code file changes?

I'm developing a VS Code extension following the vscode-extension-samples/helloworld-sample.
Question:
Is there a way to Hot Module Replace or otherwise "patch" the source code loaded by the host window?
Alternatively is there a way to reload the host window on source code changes?
When running the Run Extension launch configuration, tsc is executed in --watch mode watching for file changes and a new VS Code window is launched acting as the in-development-extension's host.
Expectation:
Updating the extentions's source code (e.g. extension.ts) updates the hosted extension's behaviour accordingly.
Actual:
Updating the extentions's source code dosn't have any effect in the hosted extension's behaviour.
Notes:
Updating the extentions's source code and then manually hitting Ctrl + R to reload the extension host window seems to "reload" the latest version of the extension's source code too, updating the hosted extension's behaviour as expected.
Here's my current config source code:
// launch.json
{
"version": "0.2.0",
"configurations": [{
"name": "Develop Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceFolder}"],
"outFiles": ["${workspaceFolder}/dist/**/*.js"],
"preLaunchTask": "npm: dev",
"postDebugTask": "Terminate All Tasks",
},
]
}
// tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "dev",
"detail": "Launch extension for local development in a new (host) VS Code window.",
"problemMatcher": "$tsc-watch",
"isBackground": true,
"presentation": { "reveal": "always" },
"group": {
"kind": "build",
"isDefault": true,
},
"icon": { "id": "tools" },
},
{
"label": "Terminate All Tasks",
"detail": "Stop all running tasks.", // e.g. useful for endless tasks like file watchers
"command": "echo ${input:terminate}",
"type": "shell",
"problemMatcher": [],
"icon": { "id": "stop-circle" },
},
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll",
},
],
}
There's no automatic reload of the extension development host. You have to do it manually.

VS CODE / MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file

I've tried many different ways but I get the error MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file. in Visual Studio code when trying to run my Net Core.
I think I have this configured correctly. The project builds with no errors. I even tried building a new empty project and still get the error.
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": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/API/API/bin/Debug/net5.0/API.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"serverReadyAction": {
"action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)"
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
]
}
Tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"command": "dotnet",
"type": "shell",
"args": [
"build",
// Ask dotnet build to generate full paths for file names.
"/property:GenerateFullPaths=true",
// Do not generate summary otherwise it leads to duplicate errors in Problems panel
"/consoleloggerparameters:NoSummary"
],
"group": "build",
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}

NestJS/VSCode Debugging not working in domain code

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

VSCode debugger not working in Jest tests

I'm struggling to get the Visual Studio Code debugger working in with Jest tests.
Here is my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest All",
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
"args": ["--runInBand"],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"sourceMaps": true
}
]
}
Here are my Jest tests with a couple of breakpoints:
When I hit the green play button to run the tests with the debugger, the breakpoints are never hit.
Any help would be appreciated
Personnally I use this configuration
{
"name": "Launch e2e test",
"type": "node",
"request": "launch",
"env": {
"NODE_ENV": "test"
},
"args": [
"--colors",
"--config=${workspaceFolder}/jest-e2e.config.js",
"--runInBand",
"--coverage"
],
"runtimeArgs": [
"--nolazy"
],
"windows": {
"program": "${workspaceFolder}/node_modules/jest/bin/jest",
},
"outputCapture": "std",
"internalConsoleOptions": "openOnSessionStart"
}
Change jest-e2e.config.js by your configuration file. And remove or keep coverage
Like Laura Slocum said you will certainly have problem with line number. In my case personnaly think that the problem come from the jest configuration, the transform :
transform: {
"^.+\\.(t|j)s$": "ts-jest"
},
This configuration let's me debug the jest test. Unfortunately hitting a breakpoint in the component does not show the correct line, even though it is stepping through the correct code. I believe this is probably a VSCode error though
{
"name": "Jest", // This is the configuration name you will see in debug sidebar
"type": "node",
"request": "launch",
"port": 5858,
"address": "localhost",
"stopOnEntry": false,
"runtimeExecutable": null,
"env": {
"NODE_ENV": "development"
},
"console": "integratedTerminal",
"preLaunchTask": "compile",
"runtimeArgs": [
"--inspect-brk", // node v8 use debug-brk if older version of node
"${workspaceRoot}/node_modules/.bin/jest",
"--watch",
"--bail",
"--runInBand"
],
"cwd": "${workspaceRoot}"
},
I had the same problem with line numbers being off. In the source file I had almost 30 lines of requires, and the test file that loaded in the debugger added a blank space between each require. So the file that got loaded in vscode was about 60 lines longer.
I found this post that fixed my problem: Debugging Jest Tests in VS Code: Breakpoints Move
The problem for me was the value of the program attribute in launch.json. If your launch.json is as follows:
"program": "${workspaceFolder}/node_modules/jest/bin/jest"
Check if ${workspaceFolder}/node_modules/jest/bin/jest is actually valid. For me, the node_modules did not exist here, but in a subdirectory of workspaceFolder.
The following is the only launch.config that worked for me after trying out everything else :|
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Jest",
"program": "${workspaceRoot}/node_modules/jest/bin/jest.js",
"args": [
"-i"
],
"skipFiles": [
"<node_internals>/**/*.js", "node_modules",
]
}
]
}
If you are using transformers like babel or swc to transform your tests before running the actual tests, the debugger in vscode may not work.
For me I'll just use the debugger.

Chain pre-launch tasks in VS Code

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.