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

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

Closed
colinaaa opened this issue Sep 23, 2024 · 2 comments · Fixed by #7968
Closed
Labels
bug Something isn't working

Comments

@colinaaa
Copy link
Contributor

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
@colinaaa colinaaa added bug Something isn't working pending triage The issue/PR is currently untouched. labels Sep 23, 2024
@chenjiahan chenjiahan removed the pending triage The issue/PR is currently untouched. label Oct 8, 2024
@ckken
Copy link

ckken commented Oct 11, 2024

class no work:

classDemo.js

export class ClassDemo {
  log() {
    console.log(`ClassDemo.name`)
  }
}
export default new ClassDemo()

App.js

import classDemo from './classDemo'
classDemo.log()

devtool

Image

@ckken
Copy link

ckken commented Oct 11, 2024

class no work:

classDemo.js

export class ClassDemo {
log() {
console.log(ClassDemo.name)
}
}
export default new ClassDemo()

App.js

import classDemo from './classDemo'
classDemo.log()

devtool

Image

in build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants