Hi i have built an app using angular-cli and I am trying to debug it using vs code and Debugger for chrome extension. After a while I was able to make it work, well kind of. What happens is that i can set a break-point in my typescript class but it gets placed on a wrong line number like source map is incorrect.
Debug process - open terminal ng serve than go to debug tab and click F5 in vscode
I have the following:
I use LaunchChrome configuration
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
},
{
"name": "AttachChrome",
"type": "chrome",
"request": "attach",
"port": 9222,
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"diagnosticLogging": true,
"sourceMapPathOverrides": {
"webpack:///*": "/*"
}
}
]
}
angular-cli.json
{
"project": {
"version": "1.0.0-beta.18",
"name": "frontend"
},
"apps": [
{
"root": "src",
"outDir": "./dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"test": "test.ts",
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
"styles.css",
"../semantic/dist/packaged/semantic.css"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../semantic/dist/packaged/semantic.js",
"../node_modules/chart.js/dist/Chart.bundle.js"
],
"environments": {
"source": "environments/environment.ts",
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"addons": [],
"packages": [],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"prefixInterfaces": false,
"inline": {
"style": false,
"template": false
},
"spec": {
"class": false,
"component": true,
"directive": true,
"module": false,
"pipe": true,
"service": true
}
}
}
tsconfig.json
{
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"outDir": "../dist",
"sourceMap": true,
"target": "es5",
"typeRoots": [
"../node_modules/#types"
]
}
}
I have updated to angular-cli-beta19-3 and typescript 2.0.6 and cleared cache in chrome now it works.
UPDATE: using angular 2.4.1 now
Whats funny is that it doesnt work with
"sourceMapPathOverrides": {
"webpack:///*": "${webRoot}/*"
}
defined here https://github.com/Microsoft/vscode-chrome-debug
but it works with
"sourceMapPathOverrides": {
"webpack:///C:*": "c:/*"
}
and for linux as #carpinchosaurio said
"webpack:///*": "/*"
UPDATE 2/21/2017:
With new versions of angular and typescript there is no need for source map path overrides anymore.
"#angular/compiler-cli": "2.4.8",
"#angular/cli": "1.0.0-beta.32.3",
"typescript": "2.1.6"
angular version 2.4.8
Working setup:
{
"version": "0.2.0",
"configurations": [
{
"name": "LaunchChrome",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}",
"userDataDir": "${workspaceRoot}/.vscode/chrome"
}
]
}
for anyone still interested this worked for me -
{
"name": "Launch localhost with sourcemaps",
"type": "chrome",
"request": "launch",
"url": "http://localhost:4200",
"sourceMaps": true,
"webRoot": "${workspaceRoot}/src",
"userDataDir": "${workspaceRoot}/.vscode/chrome",
"sourceMapPathOverrides": {
"webpack:///./~/*": "${workspaceRoot}/node_modules/*",
"webpack:///./src/*": "${workspaceRoot}/src/*"
}
// Uncomment this to get diagnostic logs in the console
// "diagnosticLogging": true
}
Just to emphasize more the updated answer: Currently it's not needed to have the sourceMapPathOverrides property in your launch.json. In case you are updating project from an old Angular, just remove the property and debugging will start working.
Related
I define global var in my code, like __DEV__, It can build by webpack tool. But when i press "F5" to debug the code, it runs error.
error msg: Cannot find name '__DEV__'.
// .vscode/launch.json
{
"name": "TS File",
"type": "node",
"request": "launch",
"args": [
"${workspaceRoot}/test/index.ts"
],
"runtimeArgs": [
"--nolazy",
"-r",
"ts-node/register",
],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen"
},
// webpack.config.js
plugins: [
new webpack.DefinePlugin({
__DEV__: JSON.stringify(false),
})
],
Just declare it somewhere, better at the entry point.
declare global {
var __DEV__;
}
Debugger doesn't work on vue application(javascript). I put the breakpoints in the component part, but it doesn't work
launch.json: (for Debugger for Chrome)
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}
]
}
terminal:
Error processing "breakpointLocations": Error: Script not found
at Client.processMessage (/home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/noice-json-rpc/lib/noice-json-rpc.js:66:36)
at LoggingSocket.<anonymous> (/home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/noice-json-rpc/lib/noice-json-rpc.js:42:48)
at LoggingSocket.emit (events.js:208:15)
at Receiver.receiverOnMessage (/home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/ws/lib/websocket.js:789:20)
at Receiver.emit (events.js:203:13)
at Receiver.dataMessage (/home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/ws/lib/receiver.js:422:14)
at /home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/ws/lib/receiver.js:379:23
at /home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/ws/lib/permessage-deflate.js:298:9
at /home/user/.vscode/extensions/msjsdiag.debugger-for-chrome-4.12.8/node_modules/ws/lib/permessage-deflate.js:376:7
at afterWrite (_stream_writable.js:484:3)
I edited launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "vuejs: chrome",
"port": 9222,
// "url": "http://localhost:8080",
"webRoot": "${workspaceFolder}/src",
"urlFilter": "http://localhost:8080/*"
/*"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}*/
}
]
}
and open in browser new tab - about:blank, after click on it in CALL STACK row, and open localhost:8080 in this(about:blank) tab
I want to use the VSCode debugger and want to set the environment variables before launching the app. The configuration in the Launch folder looks something like this.
{
"name": "Launch on iOS",
"type": "nativescript",
"request": "launch",
"platform": "ios",
"appRoot": "${workspaceRoot}",
"sourceMaps": true,
"watch": true,
"environment": [
{
"BUILD_ENV": "local"
}
]
}
This doesn't seem to work though. I am using a Mac.
Perhaps this works:
"env": {
"BUILD_ENV": "local"
}
or
"envFile": "${workspaceFolder}/.env",
or
"osx": {
"environment": [
{ "name": "",
"value": ""
}
]
},
See platform-specific properties.
I'm trying to launch multiple programs that need to talk to each other in the debugger in VS Code and created a launch.json with a compound that launches each of the executables. The programs launch simultaneously and all try to connect to the host at the same time. Is there any way in VS Code to explicitly set some sort of time delay between launch of each of the executables, say 250ms or so?
{
"version": "0.2.0",
"configurations": [
{
"name": "Host",
"type": "cppdbg",
"request": "launch",
"program": "/home/user/build/bin/host",
"args": [],
"stopAtEntry": false,
"cwd": "/home/user/build/bin",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "Node A",
"type": "cppdbg",
"request": "launch",
"program": "/home/user/build/bin/Node_A",
"args": ["ArgA", "ArgB", "ArgC"],
"stopAtEntry": false,
"cwd": "/home/user/build/bin",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
},
{
"name": "Node B",
"type": "cppdbg",
"request": "launch",
"program": "/home/user/build/bin/Node_B",
"args": ["ArgA", "ArgB", "ArgC"],
"stopAtEntry": false,
"cwd": "/home/user/build/bin",
"environment": [],
"externalConsole": true,
"linux": {
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
}
],
"compounds": [
{
"name": "System",
"configurations": ["Host", "Node A", "Node B"]
}
]
}
Yes, you can add a prelaunch task which will sleep for x seconds.
So say you have a client and server on Node.js and the server db connection takes longer to load this causes problems with the client.
Delaying the client debugger on vscode would work like this on a Mac OS X
First create a task in the same folder as the launch.json file called tasks.json which will build out a shell command before launching the client.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Sleepdelay",
"type": "shell",
"command": "sleep 6",
"windows": {
"command": "ping 127.0.0.1 -n 6 > nul"
},
"group": "none",
"presentation": {
"reveal": "silent",
"panel": "new"
}
}
]
}
Add the following pretask to your launch.json file now to call the task
{
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Client",
"url": "http://localhost:9090",
"webRoot": "${workspaceFolder}/client/src",
"breakOnLoad": true,
"sourceMapPathOverrides": {
"webpack:///./src/*": "${webRoot}/*"
},
"preLaunchTask": "Sleepdelay"
//"runtimeExecutable": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
},
{
"type": "node",
"request": "launch",
"name": "Server",
"program": "${workspaceFolder}/server/server.js",
"envFile": "${workspaceFolder}/server/.env",
"cwd": "${workspaceFolder}/server/"
}
],
"compounds": [
{
"name": "Server/Client",
"configurations": ["Server", "Client"]
}
]
}
The sleep command is available on Linux and MAC OS X. For Windows just use this hack in place of it:
ping 127.0.0.1 -n 6 > nul
Now you have a simple method to delay the launch of the client before the server.
Complementing Jason's answer
I was getting Error
OpenError: (:) [Out-File], NotSupportedException FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
On Windows (PowerShell Terminal), and have to change the ping hack command from:
"ping 127.0.0.1 -n 6 > nul"
to:
"ping 127.0.0.1 -n 6 > $null"
I need to debug a command gulp start with VScode (I got some mapping error with babel during transpilation that I don't understand yet...). The VSCode debug default configuration aims to launch node app.js. How to modify it to trigger the gulp command?
Here is the default configuration. If anyone has hint of how can I do that, I'll be in your debt :)
{
"version": "0.2.0",
"configurations": [
{
"name": "Lancer",
"type": "node",
"request": "launch",
"program": "${workspaceRoot}/app.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"preLaunchTask": null,
"runtimeExecutable": null,
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attacher",
"type": "node",
"request": "attach",
"port": 5858,
"address": "localhost",
"restart": false,
"sourceMaps": false,
"outDir": null,
"localRoot": "${workspaceRoot}",
"remoteRoot": null
}
]
}
In your "Lancer" configuration, make the following changes.
Change program to "${workspaceRoot}/node_modules/gulp/bin/gulp.js"
Change args to ["start"]
Set a breakpoint in the task you want to debug and launch the debugger. Change 'start' to the desired task name to debug other tasks.