Skip to content

Sourcemaps break when using treeshake: 'smallest' #889

Closed

Description

@aleclarson

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?

Activity

  1. added 3 commits that reference this issue on Apr 21, 2023
    7a745b7
    ed699eb
    dc291a3
  2. xia0hj commented on Dec 28, 2023

    @xia0hj
    Contributor

    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

  3. aleclarson commented on Dec 28, 2023

    @aleclarson
    Author

    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.

  4. added a commit that references this issue on Jul 16, 2024
    86f5794
  5. github-actions commented on Jul 17, 2024

    @github-actions
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions