Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

How to Debug an Angular Application With Chrome and VS Code

DZone's Guide to

How to Debug an Angular Application With Chrome and VS Code

You can debug an Angular application with Chrome and VS Code. Of course, you can also configure Chrome to attach directly.

· Web Dev Zone
Free Resource

Get the senior executive’s handbook of important trends, tips, and strategies to compete and win in the digital economy.

In this post, I want to show you how to debug an Angular application with Chrome and VS Code.

First of all, you need to install the extension in VS Code.

You can find it here or search in the extensions tab for the plugin directly:

Image title


After installing, you probably have to enable the plugin and restart VS Code, but in the end you will see your folder structure like normal. Then, head over to the debug tab and press the button for creating you an new configuration and select the “Chrome” environment.

Image title


After doing this, the extension created a new folder (if you do not have it already) called “.vscode” with a “launch.json” in it, initially looking like this:

{ "version": "0.2.0", "configurations": [ { "name": "Launch Chrome against localhost, with sourcemaps", "type": "chrome", "request": "launch", "url": "http://localhost:8080", "sourceMaps": true, "webRoot": "${workspaceRoot}" }, { "name": "Attach to Chrome, with sourcemaps", "type": "chrome", "request": "attach", "port": 9222, "sourceMaps": true, "webRoot": "${workspaceRoot}" } ] }

Our folder structure tells us that the files are served from the root.

So, the "webRoot”: “${workspaceRoot}”” setting is good to go for us. We will open a new Chrome instance but it needs an existing running server. So, if you use something like lite-server, you can easily type “lite-server” at the root of your web application or place it in your NPM command chain in the “NPM Start” command. This is what I did.

Before we go, we need to adjust the URLs where the server is running and the URL where the Chrome instance is starting.

So, replace the port in the config file with the port from your lite-server. In my case, that's “3000.” 

Then, start the lite server and just hit “play.”

Image title

Image title



Chrome starts and you can debug your page in VS Code. Of course, you can also configure Chrome to attach directly. See here for examples.

Read this guide to learn everything you need to know about RPA, and how it can help you manage and automate your processes.

Topics:
web dev ,debug ,angular ,tutorial ,vs code ,chrome

Published at DZone with permission of Fabian Gosebrink, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}