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

sentryWebpackPlugin makes webpack forget content hashes #680

Open
josefnorlin opened this issue Feb 19, 2025 · 5 comments
Open

sentryWebpackPlugin makes webpack forget content hashes #680

josefnorlin opened this issue Feb 19, 2025 · 5 comments

Comments

@josefnorlin
Copy link

Environment

3.1.2

Steps to Reproduce

  1. Run a production build using Gitlab CI
  2. See that content hashes in dist/static/js/***.bundle.js gets regenerated every time:
  3. Removing, makes it work again:
webpackConfig.plugins.push(
   sentryWebpackPlugin({
      project: 'XXX',
      org: 'XXX',
      release: process.env.VERSION,
      include: './dist',
      dryRun: !!process.env.ANALYZE,
      rewrite: false,
  })
);
  1. Also setting realContentHash to false makes it work, but that might cause other problems:
optimization: {
      realContentHash: false,
 },

Expected Result

Should not change on each rebuild.

Actual Result

New dist/static/js/***.bundle.js files every time. Also tried rewrite: true/false to no avail.

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 19, 2025
@Lms24
Copy link
Member

Lms24 commented Feb 19, 2025

Hi, thanks for writing in! Can you please share a minimal reproduction that we can use to investigate this?

Without a full picture, my best guess would be that our plugin injects something that changes on every build dynamically, for instance the release or debugIds.

Removing, makes it work again:

Removing what?

@josefnorlin
Copy link
Author

josefnorlin commented Feb 19, 2025

Here's a minimal reproduction:
https://github.com/josefnorlin/sentry-webpack-repro

And run it on a Gitlab CI/CD process (since this is no problem running locally):

  1. Run it first like it is in Gitlab and download the build artifact.
  2. Note the file names of the artifacts.
  3. Change to add something in the console.log's in other.js
  4. Save, commit and run again in CI/CD process
  5. Compare content hash files names.

Image

  1. Then uncomment the your plugin by commenting back the lines in webpack.config.js:

`// plugins: [

// sentryWebpackPlugin({

// project: "XXX",

// org: "XXX",

// release: process.env.VERSION || "1.0.0",

// include: "./dist",

// dryRun: true, // Set to true for testing without uploading

// }),

// ],`

  1. Save and commit, let Gitlab CI/CD build again.
  2. Download artifact and see file names.
  3. Now change in other.js again by changing the string in one of the console.log's
  4. Commit and build again
  5. See all file names now changed.

Image

My short reference above to "Removing, makes it work again:" was to comment away those lines above.

Hope this clarifies things.

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 19, 2025
@Lms24
Copy link
Member

Lms24 commented Feb 19, 2025

Thanks for providing the reproduction! I can in fact reproduce this locally. in the sense that both the main.* and other.* assets get different hashes when adjusting console logs.

First off: It seems fairly logical to me that the main.* hash changes because the changed console.log from other.js gets pulled into the main. bundle.

Your Webpack plugin config is outdated, probably from a time where you used version 1 of the plugin(?). Here's an updated version:

plugins: [
  sentryWebpackPlugin({
    project: "hbbtv-client",
    org: "sveriges-television",
    release: {
      name: process.env.VERSION || "1.0.0", // <--- `release.name` is the new `release`
    }
    sourcemaps: { // <-- you probably don't need to set this at all, as we auto detect assets since v2
      assets: ["dist"],
    },
    // dryRun: true, // <-- no longer available
  }), 
],

As you can see, the release name property shifted, which meant that the plugin couldn't determine a set release name so it fell back to either an environment variable or the git commit sha to set it. This release value gets injected into every bundle. So this likely introduced randomness that led to changes in all files.

We also further inject a debug id snippet with a unique ID for each file. I think this should be deterministic as long as no file changes occur (cc @lforst to confirm) but likely there was interplay with the release.

I recommend updating your config and checking if you still get different hashes in places where you wouldn't expect this.

Note that I didn't reproduce this on Gitlab yes because frankly, if I can avoid creating yet another account I'll do that 😅

@josefnorlin-svt
Copy link

josefnorlin-svt commented Feb 25, 2025

Thank you! That, along with the correct project and auth key, solved the issue. I find it a bit strange that a misconfiguration in the Sentry setup caused the content hashes to change. Is it supposed to work this way? If so, would it be a bad idea to show a warning about it?

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 25, 2025
@josefnorlin-svt
Copy link

I've updated the code to better split concerns of main.js (index.js) and other.js (other.js) file to better show this in the project linked here:

https://github.com/svt/sentry-webpack-repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Waiting for: Product Owner
Development

No branches or pull requests

3 participants