Having trouble with debugging in Visual Studio for TypeScript (specifically Angular) projects? If Visual Studio 2017 is skipping over your breakpoints

// ============================== see updates below ============================== //

While attempting to debug a TypeScript application in Visual Studio 2017 (NOT Visual Studio Code), I encountered an issue where inserting a breakpoint on a .ts file resulted in the message: "the breakpoint will not currently be hit no executable code is associated with this line"

I have tried various solutions recommended online, but none of them have resolved the issue. This problem seems to be specific to a single project.

It's worth noting that I have another project where debugging TypeScript in Visual Studio 2017 works perfectly fine with breakpoints functioning as expected, indicating that it may not be a settings issue.

Currently, my TypeScript debug settings are controlled by tsconfig.json, and I suspect that there might be an error within that file or perhaps in my webpack.config.js file. However, this is just a speculation at this point. The content of tsconfig.json is as follows:

{
  "compilerOptions": {
    "target": "es5",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "types": [ "node", "jasmine", "core-js" ],
    "noEmitOnError": true
  },
  "compileOnSave": true,
  "exclude": [
    "node_modules",
    "wwwroot/lib",
    "bin",
    "obj"
  ]
}

The content of the webpack config file is as follows:

const path = require('path');
const webpack = require('webpack');

module.exports = {
    context: __dirname,
    resolve: { extensions: ['.ts', '.js'] }, // .ts is first so that .ts files are prefered over js file, this ensures
    // that angular 2 components are passed through the angular2-template-loader and have their templates and styles inlined
    entry: {
        'polyfills': './App/polyfills.ts',
        'main': './App/main.ts'
    },
    output: {
        path: path.join(__dirname, './wwwroot/dist'),
        filename: '[name].js',
        publicPath: '/dist/'
    },
    module: {
        rules: [

            { test: /\.ts$/, include: /App/, use: ['awesome-typescript-loader?silent=true', 'angular2-template-loader'] },
            { test: /\.html$/, use: 'html-loader?minimize=false' },
            { test: /\.css$/, use: ['to-string-loader', 'css-loader'] }
        ]
    },
    plugins: [
        new webpack.DllReferencePlugin({
            context: __dirname,
            manifest: require('./wwwroot/dist/vendor-manifest.json')
        }),
        new webpack.optimize.UglifyJsPlugin(),
        new webpack.HotModuleReplacementPlugin()
    ]
};

Lastly, I am using Microsoft.AspNetCore.SpaServices.Webpack; for enabling Webpack hot module replacement with the following setup in my startup.cs:

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
    // HMR //
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
        app.UseWebpackDevMiddleware(new WebpackDevMiddlewareOptions
        {
            HotModuleReplacement = true
        });
    }
    // HMR //

//(...) additional configuration below

If you have any insights or troubleshooting tips for this issue, please let me know!

[Feel free to request more information]

// =============================================================================== //

UPDATE #1

It appears that the Angular project integrated into Microsoft's ASP.NET Core web application project in Visual Studio 2017 with .NET v.2+ comes with working breakpoints and debugging options out of the box.

However, there's a new challenge – the project is running on Angular 4 instead of Angular 5, requiring manual updates for each package. After updating them, the breakpoints seem to work without clear explanation...

Answer №1

Encountering a similar issue, I followed your advice in Update #1 and discovered that the new Visual Studio Angular project comes with a functional debug feature.
To update my app, I simply upgraded to the latest package versions and transferred my old project into the new one, which allowed me to work with breakpoints effortlessly.

Upon inspecting the webpack.config.js file within the integrated angular app of the new VS, you'll come across this line:

        new webpack.SourceMapDevToolPlugin({
            filename: '[file].map', // Remove this line if you prefer inline source maps
            moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
        })

The SourceMapDevToolPlugin, when properly configured, offers real-time mapping that enables breakpoint usage.
It's up to you whether or not to utilize inline source maps.

Furthermore, make sure to set the property: devtool: 'inline-source-map'
And activate UglifyPlugin's sourcemaps.

After testing it out, I've noticed a few drawbacks:

  • Breakpoints aren't immediately accessible when the app starts; there is a brief delay.
  • Using breakpoints can be somewhat sluggish.
  • Enabling chrome console may interfere with breakpoints.

Answer №2

By adjusting the webpack context to the ClientApp directory (or App in TypeScript's example), I was able to successfully complete the task:

  context: path.join(__dirname, "ClientApp"),
  entry: {
    //'main': './ClientApp/main.ts'
    'main': './main.ts'
  }

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

Highcharts, put a halt to the dynamic spline graph rendering

Utilizing Angular, I successfully implemented a Dynamical Spline Graph by following the guidelines outlined in the HighCharts documentation. An important feature I would like to incorporate is the ability for the chart to pause rendering upon clicking a d ...

Issues with React Material UI Select functionality not performing as expected

I've been working on populating a Select Component from the Material UI library in React, but I'm facing an issue where I can't choose any of the options once they are populated. Below is my code snippet: import React, { useState, useEffect ...

Transforming a plain text field into an input field upon clicking a button or icon using Angular/Typescript

I am a beginner with Angular 6 and I'm trying to implement functionality where clicking a button or icon will change a text field into an input field. See the snippet of code and expected output below. Thank you in advance. <div> <mat-for ...

Steps for generating a signal that postpones the primary signal and promptly resets

I am looking to create a signal that will automatically switch to an underlying signal or memo after a specific delay, and reset immediately if the primary signal is cleared. The code snippet below illustrates my desired functionality. import { render } fr ...

Error: The function req.logIn is not recognized - Passport JS

After researching extensively, I am confident that the issue I'm facing is not a known bug. I am currently utilizing passport JS with the local strategy in my login route, employing a custom callback and invoking req.login once I confirm the user&apos ...

In Vue3, automatically infer a type for a slotProp based on the modelValue

In simplifying the component I aim to create, I have created the following code structure: // MyComp.vue <script setup lang="ts"> import { PropType, defineProps, defineEmits } from 'vue'; const props = defineProps({ modelVal ...

Setting up an nginx configuration that seamlessly integrates an Angular 4 application and a WordPress blog within the same route

Presumption: The current system is hosted on https://example.com [which is statically served from /home/centos/projects/dist.example.com] My attempt was to set up the path https://example.com/blogs to run a WordPress blog application. This is my conf ...

Struggling to extract the hours and minutes from a date in IONIC: encountering an error stating that getHours is not a recognized

I encountered an issue while trying to extract the hours and minutes from a date in Ionic. Below is the code snippet from my .html file : <ion-datetime displayFormat="HH:mm" [(ngModel)]='timeEntered1' picker-format="h:mm"></ion-date ...

Populate input fields in HTML using Angular 4

Within my angular 4 project, I am facing the challenge of setting a value in an input field and in a MatSelect without relying on any binding. Here is the HTML structure: <div class="row search-component"> <div class="col-md-5 no-padding-rig ...

The nb-install mixin is not recognized

While working with angular5, I encountered the 'No mixin named nb-install' error when running npm start or serve Module build failed: undefined ^ No mixin named nb-install Backtrace: stdin:13 in E:\mrb_bugfixes& ...

What is the proper way to manage the refresh token on the client's end within a JWT system?

Curious about what exactly occurs on the client side when the refresh token expires. Is the user directed to a login page and remains logged in, or does the client side log them out automatically? My understanding is that the refresh token is saved in an ...

Choosing between global and local Node packages can be a crucial decision that affects

Recently, I discovered that Angular 2 is installed globally on my system, but I can't remember when I did that or if it's the recommended setup. It seems redundant since Angular can be defined in each project individually. This situation has me ...

Set up a unique database in memory for every individual test

Is it feasible to create an in-memory database for each test scenario? My current approach involves using the code snippet below, which functions properly when running one test file or utilizing the --run-in-band option. import _useDb from "@/useDb&q ...

Angular 2 testing encounters an issue with ViewUtils when setBaseTestProviders() is used

Encountering an issue when utilizing the 'setBaseTestProviders(..)' method, a console error arises. Our current version of Angular is 2.0.0-rc.1. The test located at (test/areas-list.component.spec.ts) looks like this: import {setBaseTestProv ...

Retrieving backend error validation in NgRx and transferring it to the component

I am attempting to retrieve error messages from an API and display them within my form inputs so that the user can easily identify any issues with the data being submitted. API Response: { "message": "The given data was invalid.", "errors": { "na ...

React Native Async Storage: displaying a blank page issue

I am facing an issue while attempting to save my data locally using AsyncStorage, specifically with the getData method. const storeData = async (value: string) => { //storing data to local storage of the device try { await AsyncStorage.setItem(& ...

Display options based on the value selected in the preceding selection

How can I dynamically display select options in an Angular select based on a previously selected value? Take a look at the code snippet below. Here, I have implemented a conditional display of select options (Target 1/Target 2) based on the value selected ...

Implementing Dynamic Columns and Rows in GridLayout using NativeScript

My HTML code consists of two GridDatas and two buttons. When Button1 is pressed, gridData1 should be displayed, and when Button2 is pressed, gridData2 should be displayed. The number of rows and columns remains static. Here are the TypeScript snippets: g ...

Wait for the response from a post request in Angular and retrieve the value once it becomes accessible

In my current method, I am sending data to the backend and receiving information about any mutations that occurred (specifically, how many new rows were added to the database). However, when using this method in its current state, the response holds the de ...

What is the TypeScript alternative for `const x = require("somemod")();`?

When working with node.js in my TypeScript project, I'm incorporating jsreport-core. In their code, they import it using var jsreport = require('jsreport-core')(); with the trailing (). I'm interested in finding out the most effective w ...