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

Source maps off in the line numbers since 0.8.13 and in the file name since 0.8.25 (regression) #638

Closed
tskarman opened this issue Jan 3, 2021 · 6 comments

Comments

@tskarman
Copy link

tskarman commented Jan 3, 2021

First off, a big thank you for your impressive project.

While evaluating it a few days ago, I noticed that the mapped file names were off in the source maps, so I ran through a few versions after noticing source map work in your release notes. I found out that it's a regression and was introduced in version 0.8.25.
While going through the preparations for this issue, I noticed that the line numbers were also off by 1-2 lines in my case and could trace it back to version 0.8.13.

For a start, I just wanted to let you know about this, so I only have screenshots to offer in this first step.

What follows is a series of screenshots of the same call situation across versions 0.8.10 to 0.8.29. Of interest for this issue are the three top-most stack entries in the respective images:

esbuild 0.8.10 (file name in source mapping good, line numbers on point)
esbuild-0 8 10
esbuild 0.8.12 (file name in source mapping good, line numbers on point)
esbuild-0 8 12
esbuild 0.8.13 (file name in source mapping good, line numbers off (see above for correct line numbers))
esbuild-0 8 13
esbuild 0.8.14 (file name in source mapping good, line numbers off)
esbuild-0 8 14
esbuild 0.8.15 (file name in source mapping good, line numbers off)
esbuild-0 8 15
esbuild 0.8.23 (file name in source mapping good, line numbers off)
esbuild-0 8 23
esbuild 0.8.24 (file name in source mapping good, line numbers off)
esbuild-0 8 24
esbuild 0.8.25 (file name in source mapping incorrect (should be shared3.ts and not Lifecycle.js), line numbers off)
esbuild-0 8 25
esbuild 0.8.26 (file name in source mapping incorrect, line numbers off)
esbuild-0 8 26
esbuild 0.8.27 (file name in source mapping incorrect, line numbers off)
esbuild-0 8 27
esbuild 0.8.28 (file name in source mapping incorrect, line numbers off)
esbuild-0 8 28
esbuild 0.8.29 (file name in source mapping incorrect, line numbers off)
esbuild-0 8 29

Details

Building/bundling from TypeScript

The package.json entry:

...
"build:es": "esbuild ./src/index.tsx --log-level=error --minify --target=\"chrome58,firefox57,safari11,edge16\" --define:process.env.NODE_ENV='production' --bundle --sourcemap --outfile=\"./build/bundle.js\"",
...

The mismapped source code comes from a separate package and the maps in that package are generated by TypeScript (tsc).
That package was static/unmodified through all my test runs here.

The regression introduced in 0.8.13 appears to come from the minification code as the line numbers only come out wrong when I specify --minify. Using --sourcemap=inline doesn't make a difference. Version 0.8.29 is the same in both regards.

The regression introduced in 0.8.25 shows itself irrespective of --minify in all the versions I tried. So the file names always come out wrong. It's the same when specifying --sourcemap=inline.

I am sorry for putting the two issues into a single issue. Let me know if you'd like me to create a separate issue for one of the two.

Please also let me know how I can be of further assistance. I can't easily share that particular source code publicly, but maybe I can create a minimal repro given some time.

@soadzoor
Copy link

soadzoor commented Jan 4, 2021

I'm having similar troubles. Happy to share my source code privately with you @evanw , just like I did a few months ago

@evanw
Copy link
Owner

evanw commented Jan 4, 2021

Thank you for the detailed issue, and for the offer to share source code privately. I did a lot of analysis of source maps on various code bases and I think I have experienced the problem myself, so I shouldn't need a code sample. Fixing this is top priority for me and I hope to have a fix soon.

@evanw
Copy link
Owner

evanw commented Jan 6, 2021

Ok I think the issues are now fixed. Please try version 0.8.30 and let me know if it works for you or not. I'm leaving this issue open until you can confirm the fix since I don't have a way to reproduce the specific problems you encountered.

I took a little while to fix this because I haven't had a great way of debugging source map problems in the past and I figured it's time to fix that. This issue inspired me to make this: https://evanw.github.io/source-map-visualization/. Now I can actually see what I'm doing so issues like this should be much easier to fix in the future.

I believe there were two source map problems, one regression introduced in version 0.7.18 and one in version 0.8.25 (more details are in the release notes). I believe that one of the changes introduced in version 0.8.13 caused the earlier regression to start affecting you. I'm guessing it was the change to rewrite const to let in minified builds. That probably then caused esbuild to try to splice the let with a let from the previous file. At least that would explain why it would happen in that release. These were the only two problems I was able to find on my own in any case.

@soadzoor
Copy link

soadzoor commented Jan 6, 2021

@evanw All my sourcemap-related problems seem to be solved with 0.8.30, thank you very much!

Also, the generated sourcemap file is much smaller than before (with 0.8.20). It used to be ~50 MB, now it's only 10MB. But I guess that's a result from 0.8.25. Quoted from the changelog: ...This didn't affect source map correctness but it made source maps unnecessarily large...

So from my end, everything seems to be fine, thank you again for your quick fixes and the awesome esbuild itself!

I've just checked the source-map-visualization, it's very nice as well!

@tskarman
Copy link
Author

tskarman commented Jan 6, 2021

Yes, everything is coming out correctly for me in 0.8.30 - thank you!

The source-map-visualization is quite enjoyable

@evanw
Copy link
Owner

evanw commented Jan 6, 2021

It’s great to hear that everything is fixed. Sorry for the breakage. Thanks so much for the detailed issue report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants