Skip to content

Terser plugin throws error during prod build for Sentry 8.x #14091

@Perchyk

Description

@Perchyk

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which SDK are you using?

@sentry/react

SDK Version

8.35.0

Framework Version

React 17.0.2

Link to Sentry event

No response

Reproduction Example/SDK Setup

export const sentryInit = () => { Sentry.init({ dsn: 'removed it from here', release: process.env.RELEASE_HASH, ignoreErrors: [ // Some errors are ignored here but I guess it's not related ], denyUrls: [ // Chrome extensions /extensions\//i, /^chrome:\/\//i, /^chrome-extension:\/\//i, // https://bugs.webkit.org/show_bug.cgi?id=246010 /.*@webkit-masked-url:.*/, // GTM injected scripts /bat\.bing\.com\/p\/insights/i, // Branch.io related errors /cdn\.branch\.io\/branch-latest/i, // Translate google com related errors /translate\.google\.com\/translate_a/i, // Google tag manager /googletagmanager\.com\/gtag/i, ], beforeSend: (event) => { const errorTraceId = uuidV4() event.extra = { ...(event?.extra || {}), errorTraceId, registeredIdentityId: getSelectedRegisteredIdentityId(), } return event }, beforeBreadcrumb(breadcrumb, hint) { if (breadcrumb.category?.startsWith('ui')) { const target = hint?.event?.target if (target?.ariaLabel) breadcrumb.message = `${breadcrumb.message} [aria-label="${target.ariaLabel}"]` } return breadcrumb }, integrations: [ Sentry.browserTracingIntegration({ instrumentNavigation: false }), ], tracesSampleRate: 0.01, }) }

Steps to Reproduce

  1. Upgrade Sentry SDK from 7.33 to 8.x (as far as I have checked, this is reproducible in any versions from 8.0 to 8.35)
  2. Ensure the dev build / runtime works, so the upgrade is successful
  3. Try to build the project without changing any dependencies other than Sentry SDK.

Webpack version: 5.85.0. We're using TerserPlugin.swcMinify but the same result happens with default minifier and with esbuild minifier as well.

Expected Result

The project prod build runs without issues.

Actual Result

I'm receiving:

ERROR in assets/bundle.63bb6c56f341751cb4b8.js
assets/bundle.63bb6c56f341751cb4b8.js from Terser plugin

× Expression expected
╭─[179293:1]
179293 │
179294 │ /** Exported only for tests. /
179295 │ function instrumentXHR() {
179296 │ if (!types_js__WEBPACK_IMPORTED_MODULE_1_/
.WINDOW */ .m ).XMLHttpRequest) {
· ─
179297 │ return;
179298 │ }
╰────

Caused by:
0: failed to parse input file
1: Syntax Error

Apparently it doesn't like the dot right before XMLHttpRequest.

The error doesn't occur on webpack versions 5.86 and higher. However, we're blocked with the webpack version bump because bumping causes an error in another dependency that we cannot get rid of or fix at the moment, so it would be great to find a fix. Unfortunately, it's hard to understand where does this "exported only for tests" function come from, but it should be from Sentry as it happens after an upgrade attempt from 7 to 8. Also, maybe it's a tree-shaking issue?

Metadata

Metadata

Assignees

Labels

BugPackage: reactIssues related to the Sentry React SDK

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions