Error in line numbers - sourcemaps, Webpack 2 and Typescript

The issue mentioned above is observed in Chrome 59.0.3071.115 and Firefox 54.0.1

Extensive research has been conducted to obtain accurate line numbers for the Typescript source code using Webpack 2.2.1 and the open-browser-webpack-plugin. Various options have been tried by setting the devtool to different configurations:

    //https://webpack.js.org/configuration/devtool/
    //devtool: 'eval', //eval very fast but inaccurate line numbers
    //devtool: 'eval-source-map', //initially slow but rapid rebuild speed and supposedly correct line numbers (not for Typescript)
    //devtool: 'source-map', //very slow, recommended for production, most precise source maps
    //devtool: 'cheap-module-eval-source-map',
    //devtool: 'inline-source-map',

None of the devtool options provided above offer the right line number for the source code.

Displayed below is an example in Chrome DevTools with the Webpack devtool option set as "eval-source-map", which also applies to "cheap-module-eval-source-map":

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

Here we see the correct source code file, although the line number is incorrect: https://i.sstatic.net/gW2yQ.png

Similarly, Firefox presents the wrong line number:

https://i.sstatic.net/57B6C.png

Lastly, the login.component.ts file with the console.log("hello world"); on line 32:

# Angular component code here

For reference, here is my webpack.config.js:

# Webpack configuration details here

And the contents of my tsconfig.json:

# Typescript compiler options defined here

Finally, my npm package.json:

# Dependencies and scripts specified here

It is acknowledged that the line number displayed for the compiled version of the Typescript file login.component.ts in Chrome Developer Tools might not align with the original source code line numbers. Is there a way to adjust the sourcemap settings in Webpack to reflect the accurate line numbers of login.component.ts before Typescript compilation?

Answer №1

In the past, I encountered a similar issue and found a workaround by adjusting my webpack.config.js file.

devtool: 'inline-source-map'

I also made changes inside my tsconfig.json file.

sourceMap: true

However, I didn't want to release my source map publicly, so after conducting some research, I switched to using awesome-typescript-loader instead of ts-loader, which resolved the issue effectively.

I hope this solution helps. Additionally, I came across some other helpful resources:

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

Check out the latest enhancements to React and Flask Fullstack right from your web browser

Recently, I ventured into the world of React and Flask development by following a tutorial found at this link. After completing the example fullstack website project, I realized that my code mirrored exactly what was provided by the author on their Github ...

Oops! It seems like this issue is not related to npm. There may be more detailed logs available above this message

I am currently working on a project that utilizes Angular6 for the frontend. I am trying to deploy this project from a remote server to the actual server. To build the frontend, I am using the npm run build -prod command. However, I am encountering a recur ...

Exploring Angular's Http Get Service

After including an Angular service in my project, I encountered a problem where it neither gives an error nor gets called. I am unsure of the issue, especially since the second object is being called successfully. Below is the code for the controller: va ...

Create a simulated class to serve as a property within a service

Currently, I'm working on an Ionic application and have created an AlertService class with two properties: messageAlert: Alert; errorAlert: Alert; The Alert class belongs to the Ionic framework, so I cannot modify it. To mock the Alert class, I came ...

The knockout click event isn't functioning properly for a table generated by ko.computed

My goal is to connect a table to a drop-down menu. Here are the key points of what I'm trying to achieve: The drop-down should list MENUs. Each MENU can have multiple MODULES associated with it, which will be displayed in the table based on the ...

Can components be SSGed individually rather than entire pages?

I am currently working with Next.js and I am wondering if there is a way to statically generate and display the database values in the header and footer components used across all pages. While getStaticProps can generate pages statically, it doesn't ...

Determine whether the browser tab is currently active or if the user has switched to a different

Is there a way to detect when a user switches to another browser tab? This is what I currently have implemented: $(window).on("blur focus", function (e) { var prevType = $(this).data("prevType"); if (prevType != e.type) { // handle double fir ...

Unlocking the style within a .css file during an Angular unit test - here's how to do

I have been working on unit testing for an Angular app, specifically trying to access styles from a .css file within the unit test. I will share with you what I have attempted so far. component.listedIps.length=0; fixture.detectChanges(); let whitelis ...

How can I use JavaScript or JQuery to retrieve the HTML content as a string from a specific URL?

How can I extract the URL of a link from a webpage and add it to my code without an ID for that specific link? Is there a way to search based on the content within the <a> tag? ...

The output is displaying an Object instead of a numerical value in JSON

When I try running the URL in Chrome, the output I receive is: { "Train_score": { "0": 0.9892473118 }, "Test_score": { "0": 0.9831932773 } } However, when I attempt to use the following code to retrieve the JSON data using Javascript, co ...

Adding dropdown values to text area

I'm encountering a simple issue. My goal is to allow users to select values from a dropdown menu and have those values added to a text area. Additionally, users should be able to input extra content in the text area. Here's what I want: the user ...

steps to determine if a page is being refreshed

Is there a way to prevent the page from reloading when the user clicks the reload button in the browser? I attempted to use this code, but my break point is not triggering. ngOnInit() { this.router .events .subscribe((e: RouterEvent) = ...

Ways to retrieve the identifier of a specific element within an array

After successfully retrieving an array of items from my database using PHP as the backend language, I managed to display them correctly in my Ionic view. However, when I attempted to log the id of each item in order to use it for other tasks, it consistent ...

Tips for organizing JSON object data and displaying it appropriately on an HTML page

This code utilizes ajax: $("form").on("submit", function () { var data = { "action": "test" }; data = $(this).serialize() + "&" + $.param(data); $.ajax({ type: "POST", dataType: "json", url: "ajax2.php" ...

`The height attribute of the textarea element is not being accurately adjusted`

When I tried to match the width(178px) and height(178px) of my table to the width and height of a text area upon clicking a button, I encountered an issue. While setting the width works perfectly fine, the height is being set to only 17px. It seems like ...

Loading images lazily using knockout.js

I have been working on implementing lazy loading for images using knockoutjs binding. I previously successfully implemented lazy loading without the knockoutjs framework, but I am unsure of how to achieve this with knockoutjs binding. Below is my HTML code ...

The issue with Bootstrap 4 toggle not correctly hiding the following div

I am trying to hide one div when the other div is displayed using Bootstrap code. However, both divs are currently displaying and my code is not working as intended. If anyone can provide assistance, it would be greatly appreciated. <link rel="st ...

Dynamically access nested objects by utilizing an array of strings as a pathway

Struggling to find a solution for accessing nested object properties dynamically? The property path needs to be represented as an array of strings. For example, to retrieve the label, use ['type', 'label'] I'm at a roadblock wit ...

Server response did not include error details from AspnetBoilerPlate

click here to view imagehttps://i.sstatic.net/60OCQ.png When using Aspnet Boilerplate, I encountered an issue with Swagger-UI running on port 5000 and Angular requiring port 21021. I attempted to change the port number in the Angular code, but then recei ...

What should I do about typescript and ES6?

An error occurred while running my code: [0] app/components/people/details/PersonDetailComponent.ts(27,35): error TS2339: Property 'person' is missing from type '{}'. Here is the code snippet in question: export class PersonDeta ...