Skip to content

webpack/rspack: transform hook sourcemaps are dropped or not composed #616

Description

@SyMind

Describe the bug

The webpack and Rspack adapters do not preserve source maps returned by a transform hook correctly:

  1. When the loader has no input source map, the adapter discards res.map.
  2. When both an input map and res.map exist, the adapter forwards only res.map instead of composing both mapping layers, so mappings from earlier loaders are lost.

As a result, the generated bundle reports incorrect original source locations even though the transform hook returns a valid source map.

Reproduction

https://github.com/SyMind/unplugin-rspack-sourcemap-repro

pnpm install
pnpm repro

The reproduction uses unplugin@3.3.0 and @rspack/core@2.2.1. Both cases run an unplugin transform that prepends one generated line and returns the corresponding high-resolution source map. The second case also runs a preceding loader that prepends a line and returns its own source map.

Actual result:

without-input-map: expected source line 1, received line 2
with-input-map: expected source line 1, received line 2

Expected behavior

The map returned by the transform hook should be preserved. The generated statement should trace back to line 1 of src/index.js in both cases, so pnpm repro should succeed.

When an input map is also present, the adapter should compose the transform map with the input map so the complete loader chain is retained.

Root cause

Both webpack-like transform loaders currently use this callback logic:

callback(null, res.code, map == null ? map : (res.map || map))

This explicitly passes a nullish input map when no input map exists, dropping res.map. When both maps exist, it selects one map without composing them.

This is related to #154 and follows up on #561 / #562: exposing inputSourceMap makes manual composition possible, but the adapter output still does not preserve the complete transform chain by default.

A fix with regression tests is available in #615.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions