Skip to content

Conversation

grushetsky
Copy link
Contributor

This PR fixes #769.

Sentry webpack plugin injects code that includes let keyword that was introduced with ES2015. let syntax is not supported by some old browsers which are still relevant in certain cases.

The code is injected by the plugin at the final stages of bundling when webpack loaders that downgrade the syntax to the target environment (ES5) have already finished the processing. Therefore, let is kept in the bundle.

Changes:

  • Substitute let for var.
  • Wrap var variable declarations with an IIFE to keep the same scope as it was with let.

Sentry webpack plugin injects code that includes `let` that breaks in ES5-only environments.
`let` is substituted for `var` wrapped in an IIFE in order to keep the same scope for the declared variable.
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks a lot for opening this PR! As outlined in #769, for now we'll close this. If we reconsider, I'll be happy to reopen and merge it.

UDPATE: talking within the team right now if we don't simply go forward with this solution

@Lms24
Copy link
Member

Lms24 commented Jul 23, 2025

reopening (see #769 (comment)).

After reconsidering, we'll review this properly and then merge it.

@Lms24 Lms24 reopened this Jul 23, 2025
@Lms24 Lms24 requested review from a team, Lms24 and RulaKhaled and removed request for a team July 23, 2025 08:15
Copy link
Member

@Lms24 Lms24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable to me! I ran the test snapshots on my end, in addition to adding a unit test for the release and build information snippet. Everything fine so far.

However, after merging this, We'll follow up with a PR to "minify" the release and module metadata snippets. This shouldn't block you any further but it will be somewhat necessary for #761, since the added code will no longer go through minification because of the renderChunk hook timing.

@Lms24 Lms24 changed the title fix(webpack): make plugin inject ES5-friendly code fix(core): Make plugin inject ES5-friendly code Jul 23, 2025
@Lms24 Lms24 merged commit 8237ac9 into getsentry:main Jul 23, 2025
23 checks passed
@grushetsky
Copy link
Contributor Author

@Lms24, oh, adding an extra test is a good idea! Thank you for merging the fix!

renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 6, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.0.2 |


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 7, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.0.2 |


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 8, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.0.2 |


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 9, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.0.2 |


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 10, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.0.2 |


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 12, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.1.0 |


## [v4.1.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#410)

- feat(deps): Bump [@sentry/cli](https://github.com/sentry/cli) to 2.51.0 [#786](getsentry/sentry-javascript-bundler-plugins#786)
- feat(core): Add flag for disabling sourcemaps upload [#785](getsentry/sentry-javascript-bundler-plugins#785)
- fix(debugId): Add guards for injected code to avoid errors [#783](getsentry/sentry-javascript-bundler-plugins#783)
- docs(options): Improve JSDoc for options [#781](getsentry/sentry-javascript-bundler-plugins#781)
- feat(core): Expose method for injecting debug Ids from plugin manager [#784](getsentry/sentry-javascript-bundler-plugins#784)


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Aug 15, 2025
| datasource | package             | from  | to    |
| ---------- | ------------------- | ----- | ----- |
| npm        | @sentry/vite-plugin | 3.6.1 | 4.1.1 |


## [v4.1.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#411)

- fix(react-native): Enhance fragment detection for indirect references ([#767](getsentry/sentry-javascript-bundler-plugins#767))


## [v4.1.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#410)

- feat(deps): Bump [@sentry/cli](https://github.com/sentry/cli) to 2.51.0 [#786](getsentry/sentry-javascript-bundler-plugins#786)
- feat(core): Add flag for disabling sourcemaps upload [#785](getsentry/sentry-javascript-bundler-plugins#785)
- fix(debugId): Add guards for injected code to avoid errors [#783](getsentry/sentry-javascript-bundler-plugins#783)
- docs(options): Improve JSDoc for options [#781](getsentry/sentry-javascript-bundler-plugins#781)
- feat(core): Expose method for injecting debug Ids from plugin manager [#784](getsentry/sentry-javascript-bundler-plugins#784)


## [v4.0.2](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#402)

- fix(core): Make `moduleMetadata` injection snippet ES5-compliant ([#774](getsentry/sentry-javascript-bundler-plugins#774))


## [v4.0.1](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#401)

- fix(core): Make plugin inject ES5-friendly code ([#770](getsentry/sentry-javascript-bundler-plugins#770))
- fix(core): Use `renderChunk` for release injection for Rollup/Rolldown/Vite ([#761](getsentry/sentry-javascript-bundler-plugins#761))

Work in this release was contributed by [@grushetsky](https://github.com/grushetsky). Thank you for your contribution!


## [v4.0.0](https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/HEAD/CHANGELOG.md#400)

##### Breaking Changes

- (Type change) Vite plugin now returns `VitePlugin` type instead of `any`
- Deprecated function `getBuildInformation` has been removed

##### List of Changes

- feat(core)!: Remove `getBuildInformation` export ([#765](getsentry/sentry-javascript-bundler-plugins#765))
- feat(vite)!: Update return type of vite plugin ([#728](getsentry/sentry-javascript-bundler-plugins#728))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@sentry/webpack-plugin Adds Code That Breaks Old Browsers
2 participants