web-infra-dev / rspack

The fast Rust-based web bundler with webpack-compatible API 🦀️
https://rspack.dev
MIT License
9.78k stars 561 forks source link

[Bug]: The source map is not working on Sentry #7914

Open cjnoname opened 1 month ago

cjnoname commented 1 month ago

System Info

System: OS: macOS 15.0 CPU: (10) arm64 Apple M1 Max Memory: 2.03 GB / 64.00 GB Shell: 5.9 - /bin/zsh Binaries: Node: 22.8.0 - ~/.nvm/versions/node/v22.8.0/bin/node npm: 10.8.3 - ~/.nvm/versions/node/v22.8.0/bin/npm bun: 1.1.27 - /usr/local/bin/bun Browsers: Chrome: 128.0.6613.138 Safari: 18.0

Details

The source maps stopped working on Sentry. After discussing with their team, we identified that the issue was caused by an invalid source map generated by Rspack.

When testing the source map with source-map-explorer or other tools, the following error appeared:

'Your source map refers to generated column 53099 on line 39, but the source only contains 53098 columns on that line. Please verify that you are using the correct source map.'

Approximately 70% of the source map files we tested are working, while 30% have failed.

Reproduce link

No response

Reproduce Steps

https://github.com/cjnoname/rspack-reproduce

npm run s

hardfist commented 1 month ago

please provide rspack version

cjnoname commented 1 month ago

please provide rspack version

1.0.5 the latest

cjnoname commented 1 month ago

please provide rspack version

I could send you the buggy soucemap files and mjs files via email or whatever tools but I don't want to share them with public.

gitim commented 1 month ago

I think this is the same issue as https://github.com/web-infra-dev/rsbuild/issues/3433 we found that source map stopped generated properly since 1.0.1 version (probably after https://github.com/web-infra-dev/rspack/pull/7647). @cjnoname, you can try the 1.0.0 version of rspack to identify when it was broken.

cjnoname commented 1 month ago

I think this is the same issue as web-infra-dev/rsbuild#3433 we found that source map stopped generated properly since 1.0.1 version (probably after #7647). @cjnoname, you can try the 1.0.0 version of rspack to identify when it was broken.

Apologies, I haven't had time to test it with version 1.0.1, but I’m quite sure it was working before when I tested it.

cjnoname commented 1 month ago

@hardfist

This is a significant issue since Sentry is the primary monitoring tool for many companies, and I hope someone can assist in looking into it.

Verifying the issue is straightforward - a single command line should work:

npx source-map-explorer index.mjs index.mjs.map

github-actions[bot] commented 1 month ago

Hello @cjnoname, sorry we can't investigate the problem further without reproduction demo, please provide a repro demo by forking rspack-repro, or provide a minimal GitHub repository by yourself. Issues labeled by need reproduction will be closed if no activities in 14 days.

hardfist commented 1 month ago

@hardfist

This is a significant issue since Sentry is the primary monitoring tool for many companies, and I hope someone can assist in looking into it.

Verifying the issue is straightforward - a single command line should work:

npx source-map-explorer index.mjs index.mjs.map

@cjnoname I can't investigate more without any reproductions, maybe you should try upgrade to 1.0.5 to see whether the sourcemap problem is solved

cjnoname commented 1 month ago

@hardfist This is a significant issue since Sentry is the primary monitoring tool for many companies, and I hope someone can assist in looking into it. Verifying the issue is straightforward - a single command line should work: npx source-map-explorer index.mjs index.mjs.map

@cjnoname I can't investigate more without any reproductions, maybe you should try upgrade to 1.0.5 to see whether the sourcemap problem is solved

https://github.com/cjnoname/rspack-reproduce

You can find the issue with a simple command: "npm run s".

I am not sure if this is the only issue causing the sourcemap to break, or if there might be other issues as well.

yuzhva commented 1 month ago

maybe you should try upgrade to 1.0.5 to see whether the sourcemap problem is solved

Hey hi, guys 👋

Would like to confirm that the latest v1.0.5 has a broken source map.

We upgraded from 0.7.5 to 1.0.3 and noticed an issue with the broken source-map - there is a big % of [no source] code based on source-map-explorer package analysis. (NOTE: you need to run the package with --no-border-checks key to process the broken source maps completely, e.g: npx source-map-explorer --no-border-checks ./dist)

So we downgraded all @rspack packages to stable v1.0.0

hardfist commented 1 month ago

@yuzhva @cjnoname sorry for the inconvenience and reproduction, confirmed it's a bug we are gonna fix it ASAP.

cjnoname commented 1 month ago

@yuzhva @cjnoname sorry for the inconvenience and reproduction, confirmed it's a bug we are gonna fix it ASAP.

I’ve put together a minimal reproduction repository last night. While I haven't done something exactly like this before, it should accurately represent the issue.

https://github.com/cjnoname/rspack-reproduce

run "npm run s" can present this issue.

Not sure if it's the only issue on sourcemap or not.

SyMind commented 1 month ago

I am currently investigating this issue.

SyMind commented 1 month ago

@cjnoname Currently, it looks like the issue with the source map is caused by the swc minifier. Please use the Terser Webpack Plugin to handle code minification first.

If the issue persists, there may be other factors causing the source map generation error. Please provide additional repos to reproduce the problem.

SyMind commented 1 month ago

In this repository, you can observe that the source maps generated by SWC cause errors in source-map-explorer. https://github.com/SyMind/swc-minifier-source-map-bug

cjnoname commented 1 month ago

In this repository, you can observe that the source maps generated by SWC cause errors in source-map-explorer. https://github.com/SyMind/swc-minifier-source-map-bug

Thank you for investigating this issue. I understand that the SWC minifier is also maintained by your team, correct?

Could you let us know if there are any plans to address this issue in the near future? We are willing to wait a few days if necessary.

We are experiencing poor performance with the Terser Webpack Plugin, which we would prefer not to revert to.

Do you have an estimated timeline for a fix?

Thanks

SyMind commented 1 month ago

@cjnoname I'm not certain if the issue is actually caused by the SWC minifier. Could you please try using the Terser Webpack Plugin and see if the problem persists?

SyMind commented 1 month ago

@yuzhva Please provide the a demo to reproduce the issue.

cjnoname commented 1 month ago

@cjnoname I'm not certain if the issue is actually caused by the SWC minifier. Could you please try using the Terser Webpack Plugin and see if the problem persists?

The issue persists even after I turned off the minimizer and disabled output: module. It still occurs. You can easily check it in my repo by adjusting the rspack.config.js file.

SyMind commented 1 month ago

@cjnoname Please don't turn off the minimizer. I've tried this before, and I found that some modules in node_modules have source map comments. This causes source-map-explorer to throw errors.

SyMind commented 1 month ago

@cjnoname You can see the code in source-map-explorer here: https://github.com/danvk/source-map-explorer/blob/master/src/lib/explore.ts#L208

cjnoname commented 1 month ago

@cjnoname You can see the code in source-map-explorer here: https://github.com/danvk/source-map-explorer/blob/master/src/lib/explore.ts#L208

It works, but it's running much slower than before. Could you help me report this issue to SWC?

SyMind commented 1 month ago

@cjnoname Yes. If you can confirm that the issue is caused by the SWC minifier, I will continue to work on it.

cjnoname commented 1 month ago

@cjnoname Yes. If you can confirm that the issue is caused by the SWC minifier, I will continue to work on it.

Yeah... Terser Webpack Plugin works fine for now. Please go ahead.

yuzhva commented 1 month ago

Here is a fork with an example for source-map "investigation": https://github.com/yuzhva/rspack-repro/commit/7ad443cc0f37d86244fd9ca18eb4cb646fe7e063

I just forked the original repo https://github.com/web-infra-dev/rspack-repro and enabled the source map for rsbuild.config.ts and rspack.config.mjs configs:

Results of Source Map investigation:

For v1.0.5:

I will prepare the same ones for v.1.0.0 if I would be able to find some spare time today.

yuzhva commented 1 month ago

@SyMind cc: @cjnoname

Would like to confirm that the root cause is in swc minifiyer.

🔴 Our current configuration that does not work:

const { SwcJsMinimizerRspackPlugin } = require('@rspack/core');

optimization: {
  minimize: true,
  minimizer: [new SwcJsMinimizerRspackPlugin()],
},

🟢 There are few options that you can use to make it work:

Source Map works with one of the next configs:

  1. either disable minification:

    optimization: {
    minimize: false,
    },
  2. or pass empty array as minimizer key for config:

    optimization: {
    minimize: true,
    minimizer: [],
    },
  3. Use Terser Webpack Plugin for minimication:

    
    const TerserPlugin = require("terser-webpack-plugin");

optimization: { minimize: true, minimizer: [new TerserPlugin()], },



The Terser covers 100% of the source map, but it is very slow.

---
UPD: The `'swc-minify-webpack-plugin'` - gives the same results as `SwcJsMinimizerRspackPlugin` with a lot of broken source-map
ckken commented 1 month ago

same here

mmazzarolo commented 1 month ago

Looks like SWC fixed the issue, thanks @SyMind for posting it there! Out of curiosity, how does the rsbuild release process look like for downstream dependency updates (such as SWC)?

hardfist commented 1 month ago

Looks like SWC fixed the issue, thanks @SyMind for posting it there! Out of curiosity, how does the rsbuild release process look like for downstream dependency updates (such as SWC)?

normally we bump swc version in minor release, but if it contains hotfix bug, we may release early

cjnoname commented 1 month ago

@SyMind SWC has released the new version including the fix mate :)

cjnoname commented 1 month ago

Looks like SWC fixed the issue, thanks @SyMind for posting it there! Out of curiosity, how does the rsbuild release process look like for downstream dependency updates (such as SWC)?

normally we bump swc version in minor release, but if it contains hotfix bug, we may release early

Any plan to release a new version soon?

mmazzarolo commented 1 month ago

@cjnoname it's already available in 1.0.7

cjnoname commented 1 month ago

@cjnoname it's already available in 1.0.7

Nope

mmazzarolo commented 1 month ago

Ouch. You're right. My B.

cjnoname commented 1 month ago

Seems like this SWC version is buggy

https://github.com/swc-project/swc/issues/9592

9aoy commented 1 month ago

Seems like this SWC version is buggy

@cjnoname Thanks for your reminder 🌹 . Rspack currently does not use the functions related to this issue. If there are any problems in the future, we will follow up in time.

And it's already available in 1.0.8.

cjnoname commented 1 month ago

Seems like this SWC version is buggy

@cjnoname Thanks for your reminder 🌹 . Rspack currently does not use the functions related to this issue. If there are any problems in the future, we will follow up in time.

And it's already available in 1.0.8.

This is awesome. Much appreciated!

cjnoname commented 1 month ago

Hey @hardfist @SyMind,

It’s still not working for us due to a different issue. Please refer to the same repository to reproduce the problem.

https://github.com/cjnoname/rspack-reproduce

Thank you!

ckken commented 1 month ago

image 1.0.8

ckken commented 1 month ago

image 1.0.8

devtool: 'source-map'

mmazzarolo commented 1 month ago

I can confirm the issue is still there in 1.0.10. Just like before, source-map is broken (in many sourcemap ranges), cheap-module-source-map works fine—breaking the use of any tools such as Sentry, Datadog, etc. to analyze errors in production and making it hard (or impossible) to debug production issues. I see the issue is being discussed in other threads (e.g., https://github.com/web-infra-dev/rspack/issues/8021), is there an official issue tracking this bug and do we know if it's SWC or rspack/rsbuild-related? Is there any workaround besides downgrading to Rspack 1.0.0? Thanks!

powerfulj commented 1 month ago

This is actually a serious bug that prevents people from using Rspack normally. I hope someone can fix it soon so Rspack can return to normal use.

SyMind commented 1 month ago

Today, I checked and found that the issue with SWC still exists. Previously, I upgraded SWC and did some local testing. It might be because I modified the source-map-explorer code, which led me to mistakenly believe that the issue with SWC had been fixed.

I will continue working to resolve this issue.

cjnoname commented 1 month ago

Today, I checked and found that the issue with SWC still exists. Previously, I upgraded SWC and did some local testing. It might be because I modified the source-map-explorer code, which led me to mistakenly believe that the issue with SWC had been fixed.

I will continue working to resolve this issue.

Thanks for fixing the previous issue with Sentry package—it worked as expected. However, there's a different issue with some other packages that I'm quite certain about. I'm also a bit concerned there might be additional issues now that the original one has been resolved.

The issue can be reproduced within the same repository. https://github.com/cjnoname/rspack-reproduce

Thank you!

SyMind commented 1 month ago

@cjnoname I've released a canary version of Rspack 1.0.9-canary-5f4b3e7d-20241010033454. Could you please verify if it works correctly? Thank you!

cjnoname commented 1 month ago

@cjnoname I've released a canary version of Rspack 1.0.9-canary-5f4b3e7d-20241010033454. Could you please verify if it works correctly? Thank you!

Hey mate, I could not find your version

SyMind commented 1 month ago

@cjnoname Please use the following package to replace @rspack/core: https://www.npmjs.com/package/@rspack/core-canary/v/1.0.9-canary-5f4b3e7d-20241010033454. Update your dependencies as shown below:

"@rspack/core": "npm:@rspack/core-canary@1.0.9-canary-5f4b3e7d-20241010033454"
cjnoname commented 1 month ago

@cjnoname Please use the following package to replace @rspack/core: https://www.npmjs.com/package/@rspack/core-canary/v/1.0.9-canary-5f4b3e7d-20241010033454. Update your dependencies as shown below:

"@rspack/core": "npm:@rspack/core-canary@1.0.9-canary-5f4b3e7d-20241010033454"

It works mate, thank you

mmazzarolo commented 1 month ago

@SyMind what about us folks using Rsbuild 👼 ? Will this be included in the next release?

mmazzarolo commented 1 month ago

This change is included in rsbuild@1.0.12, right? (I see it includes rspack@1.0.9). For what is worth, it's still not working for us 😿

Ton of sourcemaps area are unreachable and can't be debugger. Downgrading Rsbuild (a lot) fixes it. I'll try to investigate a bit more, but I'm a bit lost at the moment.

Image