sentry-javascript-bundler-plugins: `ERROR: Unexpected ";"` when using sentryVitePlugin

Environment

Using: "@sentry/vite-plugin": "^2.2.0" Framework: "@sveltejs/kit": "1.20.0"

This is the config i’m using for the plugin:

sentryVitePlugin({
	org: 'my-org',
	project: 'my-project',
	authToken: env.SENTRY_AUTH_TOKEN,
	sourcemaps: {
		ignore: ['node_modules', 'vite.config.ts'],
		// Specify the directory containing build artifacts
		assets: './.svelte-kit/**'
	}
})

Steps to Reproduce

  1. Built my project

Expected Result

Build should complete with no syntax error. This has happened for over a week now. We use dependabot, so a new build runs every time the plugin gets an update.

Actual Result

It seems like Sentry is injecting some code that causes a syntax error in the transformed code.

rendering chunks (46)...[vite:esbuild-transpile] Transform failed with 1 error:
chunks/navigation.js:49:38: ERROR: Unexpected ";"

Unexpected ";"
47 |   * @returns {void}
48 |   */
49 |  const afterNavigate = /* @__PURE__ */ ;!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="21ba7d35-8a1d-4997-1126-b7ce028af103",e._sentryDebugIdIdentifier="sentry-dbid-21ba7d35-8a1d-4997-1126-b7ce028af103")}catch(e){}}();client_method('after_navigate');
   |                                        ^
50 |  
51 |  export { afterNavigate as a, beforeNavigate as b };

✓ built in 11.84s
error during build:
Error: Transform failed with 1 error:
chunks/navigation.js:49:38: ERROR: Unexpected ";"
    at failureErrorWithLog (/tech/frontend/node_modules/esbuild/lib/main.js:1636:15)
    at /tech/frontend/node_modules/esbuild/lib/main.js:837:29
    at responseCallbacks.<computed> (/tech/frontend/node_modules/esbuild/lib/main.js:697:9)
    at handleIncomingPacket (/tech/frontend/node_modules/esbuild/lib/main.js:752:9)
    at Socket.readFromStdout (/tech/frontend/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 38 (20 by maintainers)

Most upvoted comments

Let’s thank @jdk2pq for this 😄

Please check out version 2.2.2 of the package which should have the fix for this issue!

@jdk2pq Yup that seems to be it. Thank you so much!

Pretty sure this is the fix:

https://github.com/getsentry/sentry-javascript-bundler-plugins/blob/013f7ff05ca95dcbdacff1b533fd533c02e44ef4/packages/bundler-plugin-core/src/index.ts#L345-L347

const commentUseStrictRegex = 
   // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files. 
-   /^(?:\s*|\/\*(?:.|\r|\n)*\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/; 
+   /^(?:\s*|\/\*(?:.|\r|\n)*?\*\/|\/\/.*[\n\r])*(?:"[^"]*";|'[^']*';)?/;

Same is happening to me on 2.1.0 but with a slightly different syntax error: #306

@2snEM6 Just curious, is this happening locally for you and are you able to reproduce the issue? And if so, what OS are you using? Or is it only during CI/CD?

It is happening locally and in CI/CD. It does not matter if I do it in Docker with an Ubuntu image, with an Alpine image, or in my Mac machine

Additional note: Can everybody triple-double check if they have both the @sentry/vite-plugin package and @sentry/bundler-plugin-core package on version 2.2.0 in their lockfile? Thanks.

Confirmed that we (@jdk2pq) have 2.2.0 for both as well.

We have the exact same issue and error with a Vue 3 application. Strangely, we have no issues building the project locally, but when it gets built in our AWS CodeBuild CD environment, we see the error above, but with the Maska dependency

[vite:esbuild-transpile] Transform failed with 1 error:
assets/maska-!~{01w}~.js:165:26: ERROR: Unexpected ";"

Unexpected ";"
163|    }
164|  }
165|  const v = /* @__PURE__ */ ;!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="{{ our project's Debug ID }}",e._sentryDebugIdIdentifier="{{ our project's Debug ID Identifier }}")}catch(e){}}();new WeakMap(), N = (n) => {
   |                            ^
166|    setTimeout(() => {
167|      var t;

✓ built in 23.37s
error during build:
Error: Transform failed with 1 error:
assets/maska-!~{01w}~.js:165:26: ERROR: Unexpected ";"
    at failureErrorWithLog (project/node_modules/.pnpm/esbuild@0.17.19/node_modules/esbuild/lib/main.js:1636:15)
    at project/node_modules/.pnpm/esbuild@0.17.19/node_modules/esbuild/lib/main.js:837:29
    at responseCallbacks.<computed> (project/node_modules/.pnpm/esbuild@0.17.19/node_modules/esbuild/lib/main.js:697:9)
    at handleIncomingPacket (project/node_modules/.pnpm/esbuild@0.17.19/node_modules/esbuild/lib/main.js:752:9)
    at Socket.readFromStdout (project/node_modules/.pnpm/esbuild@0.17.19/node_modules/esbuild/lib/main.js:673:7)
    at Socket.emit (node:events:513:28)
    at Socket.emit (node:domain:489:12)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
    at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
·ELIFECYCLE· Command failed with exit code 1.