Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

When I develop an Angular 2 app in Typescript it compiles to Javascript files. The errors in the browser point to a line number in the .js files e.g.:

TypeError: Phone.query2 is not a function phone_list.controller.js:5:27)

However what I want is a pointer to the line in the actual .ts file.

The corresponding sourcemap files are in place and the generated .js files point to the mapfiles e.g.:

//# sourceMappingURL=phone_list.controller.js.map

I have tried debugging in Firefox, Chrome and Webstorm.

Update

To reproduce follow these steps:

git clone https://github.com/johnpapa/angular2-tour-of-heroes

install the npm packages npm i

In dashboard.component.ts add these two lines:

var test:any = null;
console.log(test.length);

This should cause throwing an error.

Run the project with npm start

In the console Chrome shows:

TypeError: Cannot read property 'length' of null
    at DashboardComponent.ngOnInit (http://localhost:3000/app/dashboard.component.js:34:37)

Which points to .js files instead of the .ts files

share|improve this question

You will have to create map for your code, then for example chrome will download the typescript too and you will see errors and debug in typescript directly. All typescript compilers can do maps

The file will be named xyz.map.js

PS: does your code contain reference to the source map?

share|improve this answer
    
Yes it does but it isn't picked up or something. I have added an example line to the question. – osi Jan 7 at 10:59
    
Did you enabled map files in debugger? – maurycy Jan 7 at 13:02
    
Yes. I have added the steps to reproduce the problem. – osi Jan 7 at 15:42

The cause of the mapping problem was the following. When I ran my project for the first time it had a bug I made in it (as shown in the question). Because of this bug the sourcemaps could not be loaded.

When I remove the bug and load the project again the mappings were made. After this the mapping worked when I introduced the bug again.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.