Can someone help me setup stacktrace-js in my webpack app?

Can someone help me setup stacktrace-js in my webpack app?

I am trying to implement stacktrace-js for my app, but am getting a little stuck.

1. I know I can get the StackTrace global object to work if I include the library as an additional script in my <head> tag, but what I want to do is this:

 import StackTrace from 'stacktrace-js'; export default function initStackTrace() { const callback = function(stackframes) { const stringifiedStack = { return sf.toString(); }).join('\n'); console.log(stringifiedStack); }; const errback = (err) => console.log(err); StackTrace.get().then(callback).catch(errback); //===> Promise(Array[StackFrame], Error) //===> callback([ // StackFrame({functionName: 'func1', args: [], fileName: 'file.js', lineNumber: 203, columnNumber: 9}), // StackFrame({functionName: 'func2', args: [], fileName: 'http://localhost:3000/file.min.js', lineNumber: 1, columnNumber: 3284}) //]) } So, importing it inside my app, which will be bundled by webpack, but this doesn't work. There is no module exports defined apparently. So what is the right way to include this library in my project? 

2. I can't seem to find any good practical examples on how to get started with this library. It has over 2000 stars, but the example documentation is pretty bare for a beginner. So, what's a good way to start with stacktrace? Apply it only to certain functions that might fail (async) or apply it to my whole bundle.js file and track everything?


Submitted July 28, 2017 at 06:08AM by madcaesar
via reddit