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

Sourcemaps break when using treeshake: 'smallest' #889

Closed
aleclarson opened this issue Apr 21, 2023 · 3 comments · Fixed by #1069
Closed

Sourcemaps break when using treeshake: 'smallest' #889

aleclarson opened this issue Apr 21, 2023 · 3 comments · Fixed by #1069
Labels

Comments

@aleclarson
Copy link

aleclarson commented Apr 21, 2023

It seems when Rollup is used for extra tree-shaking, the sourcemaps no longer trace back to correct positions in the source code. This makes breakpoints effectively useless.

You might be forgetting to feed the sourcemaps into Rollup?

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
aleclarson added a commit to aleclarson/tsup that referenced this issue Apr 21, 2023
aleclarson added a commit to alien-dom/alien-dom that referenced this issue Apr 21, 2023
aleclarson added a commit to alien-dom/alien-dom that referenced this issue Apr 21, 2023
@xia0hj
Copy link
Contributor

xia0hj commented Dec 28, 2023

I met this problem too, it might be caused by incorrect use of applySourceMap here

tsup/src/plugin.ts

Lines 156 to 166 in 322cb77

if (result.map) {
const originalConsumer = await new SourceMapConsumer(
parseSourceMap(info.map)
)
const newConsumer = await new SourceMapConsumer(
parseSourceMap(result.map)
)
const generator =
SourceMapGenerator.fromSourceMap(originalConsumer)
generator.applySourceMap(newConsumer, info.path)
info.map = generator.toJSON()

correct example: https://github.com/mozilla/source-map/blob/master/test/test-source-map-generator.js#L356-L362

Besides, default output is ./dist/index.js.map. But rollup treeshake sourcemap path is ./out.js.map, result in incorrect sources path src/index.ts. The correct one should be ../src/index.ts

I fixed these 2 bugs in #1069

@aleclarson
Copy link
Author

aleclarson commented Dec 28, 2023

In addition to @xia0hj's PR, there's also this one: #949 (by @hyrious)

I've not tested it myself. Interestingly, it's quite a bit different than @xia0hj's solution.

Copy link
Contributor

🎉 This issue has been resolved in version 8.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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