简体   繁体   中英

How to get a readable stack trace for a webpack production environment for a minified bundle with dev-tool set to source-map?

Is it possible to get a readable stack trace for a webpack production environment for a minified bundle with dev-tool set to source-map ? I am running Typescript and react with a Webpack build. An example of an exception that is being thrown is shown in the listing below:

http://localhost:8080/vendors~course-list.3042c44300bc08021f63.bundle.js:2:6029
http://localhost:8080/vendors~course-list.3042c44300bc08021f63.bundle.js:2:5067

in w in b in withRouter(b) in e in e in Suspense in div in e in e in S

In the above stacktrace the following observations can be made with the devtool option set to source-map :

  • names remain minimised, eg w, b and e.
  • minimised error locations are reported, eg line number and column numbers.

I'm using this npm package and it works great:)

https://www.npmjs.com/package/sourcemapped-stacktrace

Example:

    import * as sourceStackTrace from 'sourcemapped-stacktrace';
    ...

    const minifiedStack = new Error().stack;
    sourceStackTrace.mapStackTrace(minifiedStack, (stackTrace: string[]) => {
        // Do your thing here
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM