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

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?

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

Related

how to use vscode to debug go 1.11.x

I am new to golang, but working on go 1.11.x.
My team use go module. The first time I clone the repository, I need to run GO111MODULE=on go mod download to download dependencies modules.
Then I need to run GO111MODULE=on go run main.go to run my app.
There is no one use vscode debugger, they prefer console log instead.
Is there any way to debug go 1.11.x using vscode?
Thanks.
I found the root cause right now. It is the source code of my team, not related to vscode or go 1.11.
My working launch.json is here
{
"version": "0.2.0",
"configurations": [
{
"name": "Go debug",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}/main.go",
"env": {
// "GO111MODULE": "on"
},
"args": [],
"showLog": true
}
]
}

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

“actionssdk-smart-home-nodejs” debug with VSCode

I successfully installed the "actionssdk-smart-home-nodejs" and it works well if i launch it using the command "node index.js" within the folder "...actionssdk-smart-home-nodejs\smart-home-provider".
I need now to debug some part of the code, thus i tried to debug it using VS Code as editor and with the launch.json configured like
{
// 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": "${file}"
}
]
}
When i launch the debugger all seems to start fine, but when i use the Google Chrome browser to access the main page (http://localhost:3000/) i get as response only "Cannot GET /".
It seems like the static route defined in the file "smart-home-provider-cloud.js" app.use('/', express.static('./frontend'));
isn't matched.
So i can't figure out why launching without debugging all works fine and if a start the debugger express returns only "Cannot GET /".
I would be grateful for any help or clue for further investigation !
After long digging i found my issue. The config file for debugging was missing a config line.
{
// 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": "${file}",
"cwd":"${workspaceRoot}/smart-home-provi
}
]
}

Visual Studio Code with GO - Multiple main declarations (launch settings)

I'm new to VS code and Golang.
I have an existing project containing 2 different services - let's call one A and the second one B.
Both A and B sits under the same directory.
Whenever I try to run A or B, I get the following error :
# directory/directory/directory/A&B_Directory
./A.go:12:6: main redeclared in this block
previous declaration at ./B.go:18:6
I tried playing with the launch.json file, adding the following sections :
{
"name": "Launch Program",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "FullDirectory/A.go"
}
Also tried in the program attribute to set to ${file} and many other variations that failed.
I'd love for some direction, I'm kinda lost.
Thanks.
Disclaimer: this is not the recommended approach, I'm agree with others, you shall separate the service A and B into different directory.
Answer to your question: To launch a specific file, use the following configuration to emulate go run current-file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Run current file",
"type": "go",
"request": "launch",
"mode": "exec",
"program": "full-path-to-go.exe",
"args": ["run", "${file}"],
"showLog": true
}
]
}
Mode exec is for launching pre-built binary given in the property program (you must specify full path to go binary). Then as the arguments, just add run and filename (${file}) to property args.

Debug bundled JavaScript file in Visual Studio 2017 with gulp-sourcemaps

I have an asp.Net Core application with AngularJS code with the following task in gulpfile.js:
gulp.task("concat_app:js", function () {
return gulp.src(js_app, { base: 'wwwroot/' })
.pipe(sourcemaps.init({
loadMaps: true,
identityMap: true,
largeFile: true
}))
.pipe(concat(paths.js_app_dest))
.pipe(sourcemaps.write('.', {
includeContent: false,
mapSources: function (sourcePath, file) {
return '../' + sourcePath;
}
}))
.pipe(gulp.dest("."));
});
If I try to debug in chrome everything is working fine and also my folder structure is correct:
structure in chrome developer tools
But when I try to debug in Visual Studio 2017, it seems not to be correctly mapped, because when I set a breakpoint, it appears in other files. I have tried the same using a tsconfig.json:
{
"compileOnSave": true,
"compilerOptions": {
"allowJs": true,
"sourceMap": true,
"target": "es5",
"jsx": "react",
"outFile": "wwwroot/js/app.js"
},
"include": [
"wwwroot/ngApp/*.js",
"wwwroot/ngApp/**/*.js"
],
"exclude": []
}
This generates a mapfile like this:
{
"version": 3,
"file": "app.js",
"sourceRoot": "",
"sources": [ "../ngApp/_app.js", "../ngApp/_config/appConfig.js" "..." ],
"names": [],
"mappings": "AAAA,CAAC;IACG,YAAY,..."
}
Here also it seems to be mapped somehow wrong, I set a breakpoint, it appears somewhere else. Also my webapplication is stopped, but I can't continue in Visual Studio.
I would prefer to use gulp-sourcemaps, but I had a hard time setting the right directory. Can this be a part of the problem, because my gulpfile.js is not located in the wwwroot-folder? project in visual studio
EDIT: It seems when using tsconfig the breakpoint is always set in the first file (_app.js). What am I missing here?

Resources