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

Try RAD Studio for FREE!  It’s the fastest way to develop cross-platform Native Apps with flexible Cloud services and broad IoT connectivity. Start Your Trial Today!

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.

Get Your Apps to Customers 5X Faster with RAD Studio. Brought to you in partnership with Embarcadero.

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.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

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

{{ parent.tldr }}

{{ parent.urlSource.name }}