Skip to content

[Bug]: this.sourceMap in the LoaderContext is false when using SourceMapDevToolPlugin #7952

@colinaaa

Description

@colinaaa

System Info

System:
OS: macOS 14.6.1
CPU: (12) arm64 Apple M2 Max
Memory: 30.78 GB / 96.00 GB
Shell: 3.7.1 - /opt/homebrew/bin/fish
npmPackages:
@rspack/cli: ^1.0.5 => 1.0.5
@rspack/core: ^1.0.5 => 1.0.5

Details

I'm using custom configuration of SourceMapDevToolPlugin, both Webpack and Rspack documentation shows that I should set devtool: false.

https://webpack.js.org/plugins/source-map-dev-tool-plugin/#root
https://rspack.dev/plugins/webpack/source-map-dev-tool-plugin

But after I set devtool: false, I found the source-map is not correctly generated.

After dive into the compilation process, I found that is caused by the this.sourceMap changes to false in my custom loader.

// loader.js
export default function(content) {
  const callback = this.async()
  const result = transform(content, { sourceMap: this.sourceMap }) // this.sourceMap === false
  callback(null, result.code, result.map) // result.map === false, result in no source-map generated
}

The Rspack directly use devtool to setup loaderContext.sourceMap:

loaderContext.sourceMap = compiler.options.devtool
? isUseSourceMap(compiler.options.devtool)
: false;

But Webpack will update the value in the SourceMapDevToolModuleOptionsPlugin:

https://github.com/webpack/webpack/blob/dae16ad11e2d2accddc549a92082da3d2e667b01/lib/SourceMapDevToolModuleOptionsPlugin.js#L31

Reproduce link

https://github.com/colinaaa-reproductions/rspack-loader-context-sourcemap

Reproduce Steps

  1. Run pnpm install
  2. Run pnpm build:webpack
  3. Run node webpack-dist/main.js // show true
  4. Run pnpm build:rspack
  5. Run node rspack-dist/main.js // show false

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions