Skip to content

Show TypeScript line numbers in stack traces #2417

Closed

Description

@tjvantoll

Currently stack traces show JavaScript line numbers instead of TypeScript line numbers. This makes debugging difficult, and it’s also a tricky thing for beginners to understand. I’m adding a debugging section to the Getting Started Guide, and I’m having a heck of a time trying to explain how this works to new users.

You can recreate this by starting a new project that uses TypeScript.

tns create Whatever --ng
cd Whatever
tns run ios --emulator --watch

And then doing something silly like this in your TypeScript code.

throw Error("Boom!");

You‘ll see a stack trace that gives line numbers in the compiled JavaScript code, and not the source TypeScript files.

CONSOLE ERROR file:///app/tns_modules/trace/trace.js:160:30: ns-renderer: Error in :0:0 caused by: Boom!

	AppComponent@file:///app/app.component.js:6:20

Activity

  1. dcarrot2 commented on Oct 15, 2018

    @dcarrot2

    I started to take a look at this by seeing if we could introduce a package like source-map-support to accomplish this, but since we're dealing with an embedded V8 runtime, it immediately blows up trying to import the path module. Perhaps a possible approach would be to replicate the implementation of that package and utilize NS's file system abstractions to read the source maps? Curious to see if anyone else has started looking into the best approach for this.

  2. stevenspiel commented on Jan 18, 2019

    @stevenspiel

    This would be very helpful!

  3. added this to the 6.0.0 milestone on May 22, 2019
  4. farfromrefug commented on May 23, 2019

    @farfromrefug
    Contributor

    @dcarrot2 actually source-map-support works perfectly fine on Android/v8. It is actually made for it.
    It won't work however with the iOS runtime.See that issue NativeScript/ios-jsc#1135

    Here is an example of reading external source map in android {N} app:

    const currentApp = knownFolders.currentApp();
    require('source-map-support').install({
        environment: 'node',
        handleUncaughtExceptions: false,
        retrieveSourceMap(source) {
            const sourceMapPath = source + '.map';
            const sourceMapRelativePath = sourceMapPath.replace('file://', '').replace(currentApp.path + '/', '');
    
            return {
                url: sourceMapRelativePath + '/',
                map: currentApp.getFile(sourceMapRelativePath).readTextSync()
            };
        }
    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions