stack-beautifierTool for decrypting stack traces coming from the minified JS code.
wat?This tool helps with translating minified/uglified stack traces from your production apps (NodeJS/react native/web) into a human readable form (with line number from your original source files) utilising the concept of source maps. This tool aims at providing a simple way of deminifying stack traces from a command line interface as opposed to other great existing alternatives, which provides similar functionality but require integration into a deployment process.
InstallationInstall it using npm:
npm install -g stack-beautifier
UsageBy default the tool accepts source map file as an argument and reads stack trace from the standard input and the prints out the translated stack trace to the standard output. The default behaviour can be altered by using the following command line options:
V8 stack trace:
TypeError: Assignment to constant variable. at <anonymous> (app.bundle.js:34:612) at b (app.bundle.js:11:3018) at d (app.bundle.js:8:1074) at <anonymous> (app.bundle.js:1:5)
JSC (react-native) stack trace:
To do so on android you can add the following snippet to your
project.ext.react = [ extraPackagerArgs: ['--sourcemap-output', file("$buildDir/outputs/index.android.js.map")] ]
Note that it has to be added before the
apply from: "../../node_modules/react-native/react.gradle"line. After a successful build the sourcemap will be located under
Generate source map from the application sourcesIf you don't have access to the source map file there is still hope. You can checkout the version at which the bundle has been generated and run the following command for android:
react-native bundle --platform android --entry-file index.js --dev false --reset-cache --bundle-output /tmp/bundle.android.js --assets-dest /tmp/ --sourcemap-output index.android.js.map
or for iOS:
react-native bundle --platform ios --entry-file index.js --dev false --reset-cache --bundle-output /tmp/bundle.ios.js --assets-dest /tmp/ --sourcemap-output index.ios.js.map
Note that it is crutial that all the dependencies from
node_moduleare at the same version as when the JS bundle has been generated, otherwise the source map may not give you the correct mapping. We recommend using yarn that helps in ensuring reproducable JS bundle builds.
app.js.mapfile and the stack trace is save in
mytrace.txtand looks as follows:
Now you can call the following command in order to get the deminified stack trace printed: