Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show TypeScript line numbers in stack traces #2417

Closed
tjvantoll opened this issue Jan 12, 2017 · 3 comments
Closed

Show TypeScript line numbers in stack traces #2417

tjvantoll opened this issue Jan 12, 2017 · 3 comments

Comments

@tjvantoll
Copy link
Contributor

tjvantoll commented Jan 12, 2017

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
@dcarrot2
Copy link

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.

@stevenspiel
Copy link

This would be very helpful!

@farfromrefug
Copy link
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
Projects
None yet
Development

No branches or pull requests

10 participants