How can I debug an Angular multi-project workspace in VSCode using the VS Code - Debugger for Chrome? After the migration to an Angular multi-project workspace, the debugging does not work anymore. I get the following message if I set a breakpoint.
Breakpoint set but not yet bound
I found a blog post about this topic: "Visual Studio Code Breakpoints for Angular Multi-Project Workspace". I added the following to my launch.json
, I replaced "webRoot": "${workspaceRoot}""
with "webRoot": "${workspaceFolder}"
:
{
"name": "Launch new-app in Chrome against localhost (with sourcemaps)",
"type": "chrome",
"request": "launch",
"runtimeExecutable": "/usr/bin/chromium-browser",
"runtimeArgs": [
"--disable-extensions"
],
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"/./*": "${webRoot}/projects/new-app/*",
"/src/*": "${webRoot}/projects/new-app/src/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*",
},
}
I also replaced new-app
with the correct app name, but it does still not work.
The folder structure:
Can anyone help me to get this working?
You can work with multiple project folders in Visual Studio Code with multi-root workspaces. This can be helpful when you are working on several related projects at one time.
You can simply do File>New Window and open the other project in the new window. Because after you close VSCODE and launch it again it opens only one of these two windows. But with workspace you keep both.
I get this working by using the .scripts
command to find out the correct paths for the sourceMapPathOverrides
property.
{
"name": "Launch editor in Chrome against localhost (with sourcemaps)",
"type": "chrome",
"request": "launch",
"runtimeExecutable": "/usr/bin/chromium-browser",
"runtimeArgs": [
"--disable-extensions"
],
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}",
"sourceMaps": true,
"sourceMapPathOverrides": {
"webpack:/*": "${webRoot}/projects/apps/editor/*",
"webpack:///./src/*": "${webRoot}/projects/apps/editor/src/*",
"/*": "*",
"/./~/*": "${webRoot}/node_modules/*",
},
}
i'm using angular 10 workspace with app & library, and i was having trouble setting breakpoints in my library.
i needed to tell "ng serve" to include vendor sourcemaps...
add a "sourceMap" object to your "angular.json" under projects / "my-app" / architect / "serve" / options:
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "app:build",
"sourceMap": {
"scripts": true,
"styles": true,
"vendor": true
}
},
ng build my-library
ng serve my-app
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": [
{
"type": "chrome",
"request": "launch",
"name": "my-app",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}/projects/my-app",
"sourceMaps": true,
}
]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With