Versions:
Angular CLI: 11.2.11
Node: 14.16.0
VS Code: 1.59.0
Chrome: 92.0.4515.131
Debugger for Chrome (Nightly): v2020.2.15300
JavaScript Debugger (Nightly): v2021.8.217
(No other VS Code extensions loaded)
Environment
Windows 10 - Running as limited user. Not able to install anything but approved software, meaning, I'm stuck with the version of Node above, I can upgrade VS Code, but not install a specific version, etc.
launch.json:
{
"name": "Launch PWA-Chrome",
"request": "launch",
"type": "pwa-chrome",
"url": "http://localhost:4200/",
"webRoot": "${workspaceFolder}"
},
{
"name": "Attach to Chrome",
"port": 9222,
"request": "attach",
"type": "pwa-chrome",
"webRoot": "${workspaceFolder}"
}
How, When:
Research and what I've tried:
Angular builds optimizes scripts using various strategy. You should disable it. Use the following configuration settings. The key is to disable build optimization and minification. After your debugging session, you can restore them back to original values.
"sourceMap": true,
"buildOptimizer": false,
"optimization": false,
"serviceWorker": false
If the above doesn't work, try this combination explicitly disables optimizations for each resource type
"sourceMap": true,
"buildOptimizer": false,
"serviceWorker": false,
"optimization": {
"scripts": false,
"styles": false,
"fonts": false
}
Further read: https://angular.io/guide/workspace-config#optimization-configuration
VS Code uses a file called launch.json. Make sure the file has correct configuration. Following is a sample config. Tweak the details for your app (ensure that you use launch/debug configuration debug-my-pwa-app from your VS Code)
{
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "debug-my-pwa-app",
"url": "http://localhost:4200",
"webRoot": "${workspaceFolder}"
}
]
}
Are you able to debug by just puttting:
// ... code
debugger
// ... code
, inside you code?