Ways to troubleshoot an Angular application utilizing Angular-CLI with webpack

I previously used [email protected] and recently updated to angular-cli@webpack beta.11. After making several custom changes, I finally managed to get it working.

However, the issue now is that I am unable to debug my Angular application using Webstorm and Chrome Debugger because I am not seeing any ts files when running ng serve. When I was using [email protected], debugging my app with the Jetbrains Plugin was simple.

What steps should I take to debug my Angular app with Webstorm and the Chrome Debugger while using ng serve?

Answer №1

How to effectively debug with angular/cli

The latest version of angular/cli now utilizes webpack, which no longer compiles the ts files to a local directory like 'dist' as it did before (up to beta 1.0.0-beta.10). Instead, it uses a memory-like approach.

If you're looking for the ts Files, you can locate them in the "Sources" tab within Chrome Developer Tools.


(Fresh) Approach for angular/[email protected] and above versions

Note: This solution has been tested on versions 1.0.0-beta.26 and 1.2.1

Note: In this example, I've used port 5321 instead of 4200. Adjust accordingly based on your setup.

Effective Debugging with Chrome Developer Tools

While you have ng serve running (also utilized in npm start), you'll find your sources under "webpack://" in the Chrome Developer Tools:

https://i.sstatic.net/C32XU.png

Debugging Your Angular 2 App seamlessly with angular/cli using JetBrains IDE

To streamline your debugging experience, simply adjust your Run/Debug Configuration in Webstorm/PHPStorm as follows:

  1. Set your Remote URL Path of your project directory to webpack://.
  2. Set your Remote URL Path of your src directory to webpack://./src

https://i.sstatic.net/xeKHG.png


(previous) Method for [email protected] - .14

Debugging via Chrome Developer Tools

When running ng serve (also employed in npm start), navigate to the Chrome Developer Tools section to access your sources under "webpack://":

https://i.sstatic.net/1g1F8.png

Enhanced Debugging of Your Angular 2 App with angular-cli@webpack using JetBrains IDE

To enhance your debugging process, tweak your Run/Debug Configuration in Webstorm/PHPStorm by setting your Remote URL Path of your project directory to:

On Mac OSX: webpack:////Users/...FULL_PATH..

Or

On Windows: webpack:///C:/...FULL_PATH..

Note: On Windows, use only 3 slashes, and on Mac, employ 4 slashes after "webpack:"

You can also verify your Path by visiting http://localhost:4200/main.map and searching for any ".ts" File. Copy the path of the file and paste it into your IDE Configuration Dialog effortlessly.

https://i.sstatic.net/5gNij.png

UPDATE: You may need to map the path by adding "/src" to your src folder as well. Thanks @born2net

Enjoy the process!

Answer №2

Success! I finally got it working by mapping both the root and src directories. Check out the link below for more information:

I hope this helps someone else facing a similar issue.

https://i.sstatic.net/FJeyC.png

Also, don't forget that sometimes the debugger may not hit your breakpoint properly. To ensure it works, try adding an alert('foo') or ;debugger code just before the breakpoint.

Thanks,

I'll soon be transitioning my jspm projects to the new CLI. For Angular 2 Kitchen sink, visit: and its source can be found at: https://github.com/born2net/ng2Boilerplate Best regards,

Sean

Answer №3

Answer from 2017 regarding:

angular-cli version 1.0.0-beta.26, node version 6.9.2, operating system: macOS x64

If you're encountering issues with this, navigate to the Scripts tab in your debugger and try adjusting your URL mappings based on what you observe.

Previous solutions didn't work for me because my angular-cli version had a different way of mapping things. https://i.sstatic.net/hH6ya.png

Answer №4

What really made a difference for me was adding an extra / (forward slash) after webpack:///, making it 4 slashes instead of 3. Initially, there were only 3 forward slashes.

https://i.sstatic.net/ePtYX.png

The remote URL actually directs to the same main directory as the one on the left side, with the only difference being the webpack://// schema.

Furthermore, contrary to common recommendations, enabling the TS compiler is not necessary.

  • Operating System: MacOS
  • Angular-CLI version: 2.4.1
  • IDE: WebStorm version 2016.3

Answer №5

It's important to remember that the solutions mentioned above do not allow you to set breakpoints in the HTML files of Angular components when using IntelliJ. This feature is only available in Chrome, for some reason it seems unavailable in IntelliJ which can be frustrating.

Answer №6

To enhance your debugging experience with Angular applications, consider using Augury. This dev tool extension for web browsers can provide valuable insights and assistance.

Ready to give it a try? Install Augury by visiting the following link:

Augury allows you to easily visualize the routing hierarchy, module and component structures, and dependencies within your application. It's a helpful tool for understanding the inner workings of your Angular projects.

Check out this Inject Graph from my own project to see how these concepts come together:

https://i.sstatic.net/fvnkI.png

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How to use node-postgres to delete an object from an array

Currently working on the backend using Express and TypeScript. Postgres is the chosen database with node-postgres as the client. Within the database, there is a table called user_collection. One of its columns is collection of type JSONB, which holds an a ...

Exporting an Angular 2 component to use in a template

I am interested in creating a custom Tabs component that has the ability to display content from [root] within itself. It functions perfectly when using selectors in html tags (<tab1>), but there are instances where the selector is unknown. Since Tab ...

Switch up row values in an array and transform them into an object using SheetJS

I am struggling to format an array where each "Working Day" is represented as an object with specific details like index and start/end date. I need help manipulating the JSON data to achieve the desired structure. The package I'm currently using is: ...

What is the method to remove curly brackets from a different data category?

If I have a type like this type Z = {a: number} | {} | {b: boolean} | {c: string} | ...; Is there a way to get the same type but without {}? type Y = Exclude<Z, {}>; ⇧This will result in Y = never, because all variants can be assigned to {} and a ...

Encountering a Zone.js error when trying to load an Angular 7 app using ng serve, preventing the application from loading

Scenario: Yesterday, I decided to upgrade my Angular app from version 5.2.9 to 6 and thought it would be a good idea to go all the way to 7 while I was at it. It ended up taking the whole day and required numerous changes to multiple files, mostly due to R ...

Only show a single li element in CSS at a time

I'm working with Angular 2 and I have a list: <ul> <li *ngFor="let show of (ann)"> {{show}} </li> </ul> I want to show one item from the list every 3 seconds in an infinite loop. Here&apos ...

What is the correct way to convert a base type value to its extended type in TypeScript?

Consider the TypeScript code block below: type URLEx = URL & { custom: string; }; const url = new URL("http://localhost:3000/foo/var"); const url_x: URLEx = { ...url, custom: "hello", }; console.log(url); // Output properti ...

Troubleshooting issues with importing modules in Typescript

I've embarked on a new Node.js project using Typescript and encountered some issues. Initially, my server setup in server.ts looked like this: const express = require("express") const app = express() app.listen(3000, () => { console. ...

React component showing historical highchart data when navigating through previous and next periods

I developed this element to showcase a Highchart. It's utilized within a dashboard element that I access from an item in a list. It mostly works as intended, but not entirely. When I move to the dashboard for item A, everything functions correctly. H ...

What could be causing the issue: Unable to locate or read the file: ./styles-variables?

I'm currently following a tutorial on how to create responsive layouts with Bootstrap 4 and Angular 6. You can find the tutorial here. I've reached a point where I need to import styles-variables.scss in my styles file, but I keep encountering t ...

Encountering issues with resolving all parameters when attempting to dynamically generate a component in Angular

As I attempt to dynamically insert a BlockComponent into a GridLayoutComponent, an error is thrown: Uncaught Error: Can't resolve all parameters for BlockComponent: (?, [object Object]). This issue arises upon page load and stems from the addBlock fun ...

Viewing documents stored on the file server using the frontend interface (angular)

I am currently working on an Angular application that interacts with a .NET Core API. I have encountered an issue where the file upload process successfully uploads files to a file server, but I am unable to access these files on the front end. Despite at ...

In TypeScript Next.js 14 APP, object literals are limited to declaring existing properties

I encountered an error in my typescript next.js 14 APP. I need assistance resolving this issue, which states: Object literal may only specify known properties, and 'productPackages' does not exist in type '(Without<ProductCreateInput, Pr ...

The pattern for the input text in HTML was dysfunctional, specifically when trying to input a negative number or a

Currently delving into the world of regex, where I am exploring ways to restrict user input. After testing on regextester.com with the following pattern: The results were not as expected +10 e10 ^([-,0-9.]+) This configuration yielded successful result ...

The duration required to render DOM elements

Trying to determine the best method for measuring the rendering time of DOM elements in a web browser. Any tips? I'm currently developing an application that involves significant DOM manipulation as part of comparing the performance between Angular 1 ...

Angular obscured the referencing pointer

After updating Angular, I encountered issues with my code. Previously, the following code worked fine: @Component({ templateUrl: './some.component.html', styleUrls: ['./some.component.scss'] }) export class SomeComponent { ... p ...

Adding information to a particular index in an array using Angular 4

Why is this code not functioning properly in TypeScript? For example: views: any[] = [360001232825, 360001232845, 360001217389]; myArray:any[]; for (var i = 0; i < this.views.length; i++) { this.subscription = this.dataService.getMyD ...

The Angular framework always initializes the list items in CDK drop List starting from the initial index

Currently, I am working with the cdk Drag drop feature <div class="example-container" cdkDropListGroup> To properly understand and describe data, it is crucial to be aware of the level of variability. This can be determined by analyzing the ...

Observing with starting value

When using an observable, I am trying to filter and display a list. The input event is only fired when the user starts typing, so initially the list is not displayed. How can I set a default value for the observable this.filterLocation$ until the input eve ...

Crystal-clear TextField component in Office UI Fabric

Seeking advice on how to clear a masked text field from Office UI Fabric using a button. Does anyone have a solution for this? I attempted to set the value using a state, but unfortunately, it did not work as expected. ...