You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Oct 29, 2026. It is now read-only.
sentry-vite-plugin: enable source mapping for Web Worker source files #755
I'm using vite and the sentryVitePlugin. My app uses web workers which are imported with new Worker(new URL('./workerLineStats.ts', import.meta.url), { type: 'module' });. Vite understands that and outputs workerLineStats-LjpNa9wZ.js and a .map file.
I'm using DebugIDs for the main app, but those don't work for the web worker files. The debug output from sentry-vite-plugin includes:
[sentry-vite-plugin] Debug: Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: /workspaces/data-portal/apps/frontend/build/assets/workers/OverallStats.worker-BPsL_pTV.js
Alternatively, uploadLegacySourcemaps could be used for the web worker files, but I'm having trouble making that work as well, see below.
Edit: generalized issue to the root problem of sourcemaps for workers in Vite, rather than the specific suggested fix of uploadLegacySourcemaps globs.
Just jumping in here because we talked about this yesterday: The behaviour of the include entry (or just the string as in your case) for uploadLegacySourcemaps always was that users specify a directory and the plugin/sentry-cli would scan this directory, including sub-directories, for .map and .js files to process and upload (see doc here). So, in contrast to the newer assets option for debugIds, glob patterns were never supported (for better of for worse).
The problem with changing this is that it could break user setups that rely on the specific behaviour, so we're not yet sure if we want to do this.
In an effort to avoid this potential breakage: is there a way you could build just the worker into a specific sub directory that you can then point the plugin towards? I fully understand this isn't ideal for you and we usually don't want to tell you what to do. Just this case of combined debugID and legacy source maps upload, in the same directory, is a bit of an edge case (something, we admittedly didn't yet come across).
The problem with changing this is that it could break user setups that rely on the specific behaviour, so we're not yet sure if we want to do this.
Understandable. I'll be less prescriptive and let's refocus this issue on the root of the problem: sourcemaps for webworkers in Vite.
In an effort to avoid this potential breakage: is there a way you could build just the worker into a specific sub directory that you can then point the plugin towards? I fully understand this isn't ideal for you and we usually don't want to tell you what to do. Just this case of combined debugID and legacy source maps upload, in the same directory, is a bit of an edge case (something, we admittedly didn't yet come across).
I spent some time on this trying to modify Vite's build.rollupOptions, puzzling over why none of the worker files were processed by any of the hooks (assetFileNames, chunkFileNames, entryFileNames). Then I realized Vite has completely separate rollupOptions just for workers 🤦. This config does work to put all the workers output js/map files in a workers subdirectory:
However I still ran into a snag with uploadLegacySourcemaps. I can't get it to actually upload any sourcemaps. Here's my configuration:
sentryVitePlugin({disable: false,org: 'beck-enterprises',project: 'data-portal-frontend',release: {// Uncomment these lines to test locally (with DP_RELEASE=1) without needing an auth token or creating a releasecreate: false,finalize: false,name: `data-portal-frontend@${PACKAGE_VERSION}`,uploadLegacySourcemaps: ['build/assets/workers/','build/assets/','assets/','assets/workers/',path.resolve(__dirname,'./build/assets/workers/'),path.resolve(__dirname,'./build/assets/'),],},bundleSizeOptimizations: {excludeReplayShadowDom: true,// I don't think we have any custom elements/shadow domexcludeReplayIframe: true,// We don't have any iframes},debug: true,}),
Am I missing something? I tried every path I could think of for the legacy source maps to make sure that wasn't the issue. No source maps are uploaded for any of the worker files, and the only mention of them in sentry-vite-plugin's output are the debugId messages:
[sentry-vite-plugin] Debug: Could not determine debug ID from bundle. This can happen if you did not clean your output folder before installing the Sentry plugin. File will not be source mapped: /workspaces/data-portal/apps/frontend/build/assets/workers/LineRenderer.worker-Dk-urqO_.js
Alternatively, perhaps sentry-vite-plugin could be changed to include DebugIDs in worker source files? Since vite processes worker files with a separate rollup invocation, maybe the sentry-vite-plugin needs to hook into that as well?
Can you give this a try and report if source maps from the worker get uploaded with this config for you?
(note that the accepted type for worker.plugins must be a function of a flat array, hence I'm spreading the plugin array our sentryVitePlugin function returns).
The bad news:
Unfortunately, due to worker and main thread not sharing the global object, the debugId from the main thread is not picked up from the worker when the main thread catches errors thrown from the worker.
More good news:
You can work around this today, by also calling Sentry.init() from within your worker. There are some drawbacks (see link below) but at least you'll get source-mapped errors.
Your case gave me an idea on how we could improve the worker/main thread dynamics when the SDK is only initialized in the main thread. This would solve the drawbacks mentioned in the feature proposal.
I have a PoC of this working in the reproduction I linked above. Feel free to check it out. You can also implement this workaround yourself at the moment, with the caveat that this is largely untested and just something I threw together in 5 minutes 😅
Would appreciate your thoughts as well as some feedback if anything posted here was helpful. Whatever we end up (not) doing, we should definitely update docs for the vite plugin to ensure that the worker case is documented better.
I appreciate the help! I quite like the solution in #16974. Unfortunately I don't think I'll have time to try any of this out before I'm out of office for the next week or so. Will try after.
Is there some way we detect when vite creates a chunk for a worker? If there is, maybe we could include that debugId with the parent that loads the worker? That way the debugID would already be where we need it?
If we inject the same Sentry plugin instance into both the root and worker config, and have a way to track when it is called for a worker, we can track the debugIds for workers and include them with all other chunks.
I've just realised it's not that simple because our debugID injection uses new Error().stack to get the script URL and that wouldn't work in this case 😭
constsentryVite=sentryVitePlugin({org: "sentry-sdks",project: "javascript",});exportdefaultdefineConfig({plugins: [sentryVite],worker: {plugins: ()=>[sentryVite.worker],// <- we'll know when the plugin is used for a worker...},});
I've just realised it's not that simple because our debugID injection uses new Error().stack to get the script URL and that wouldn't work in this case 😭
yes, I think this is a hard limitation for us being smarter at build time 🤔
If we inject the same Sentry plugin instance into both the root and worker config, and have a way to track when it is called for a worker, we can track the debugIds for workers and include them with all other chunks.
Even if we could, I'm not sure if timing-wise, we know it early enough to inject anything into the main bundle(s) anymore 🤔 AFACT, the worker build is an isolated build, though happy to be proven wrong here :D
@mattico once you're back: We've updated our web worker docs with the new webWorkerIntegration approach. In there we now also mention that the plugin needs to be passed to Vite's worker build.
I'll close this issue for now. Let us know if this should be reopened.
Activity
chargome commentedon Jul 10, 2025
@mattico would generally just providing the asset path work for you?
mattico commentedon Jul 10, 2025
I suppose it would, though it would also upload dozens of unnecessary sourcemaps for all the files which have DebugIDs.
Lms24 commentedon Jul 11, 2025
Just jumping in here because we talked about this yesterday: The behaviour of the
includeentry (or just the string as in your case) foruploadLegacySourcemapsalways was that users specify a directory and the plugin/sentry-cli would scan this directory, including sub-directories, for.mapand.jsfiles to process and upload (see doc here). So, in contrast to the newerassetsoption for debugIds,globpatterns were never supported (for better of for worse).The problem with changing this is that it could break user setups that rely on the specific behaviour, so we're not yet sure if we want to do this.
In an effort to avoid this potential breakage: is there a way you could build just the worker into a specific sub directory that you can then point the plugin towards? I fully understand this isn't ideal for you and we usually don't want to tell you what to do. Just this case of combined debugID and legacy source maps upload, in the same directory, is a bit of an edge case (something, we admittedly didn't yet come across).
mattico commentedon Jul 11, 2025
Understandable. I'll be less prescriptive and let's refocus this issue on the root of the problem: sourcemaps for webworkers in Vite.
I spent some time on this trying to modify Vite's
build.rollupOptions, puzzling over why none of the worker files were processed by any of the hooks (assetFileNames, chunkFileNames, entryFileNames). Then I realized Vite has completely separate rollupOptions just for workers 🤦. This config does work to put all the workers output js/map files in a workers subdirectory:However I still ran into a snag with uploadLegacySourcemaps. I can't get it to actually upload any sourcemaps. Here's my configuration:
Am I missing something? I tried every path I could think of for the legacy source maps to make sure that wasn't the issue. No source maps are uploaded for any of the worker files, and the only mention of them in sentry-vite-plugin's output are the debugId messages:
Alternatively, perhaps sentry-vite-plugin could be changed to include DebugIDs in worker source files? Since vite processes worker files with a separate rollup invocation, maybe the sentry-vite-plugin needs to hook into that as well?
4 remaining items
Lms24 commentedon Jul 14, 2025
Okay, so I have good and bad news:
The good ones first:
(note that the accepted type for
worker.pluginsmust be a function of a flat array, hence I'm spreading the plugin array oursentryVitePluginfunction returns).The bad news:
More good news:
Would appreciate your thoughts as well as some feedback if anything posted here was helpful. Whatever we end up (not) doing, we should definitely update docs for the vite plugin to ensure that the worker case is documented better.
mattico commentedon Jul 14, 2025
@Lms24
I appreciate the help! I quite like the solution in #16974. Unfortunately I don't think I'll have time to try any of this out before I'm out of office for the next week or so. Will try after.
timfish commentedon Jul 15, 2025
Is there some way we detect when vite creates a chunk for a worker? If there is, maybe we could include that debugId with the parent that loads the worker? That way the debugID would already be where we need it?
timfish commentedon Jul 15, 2025
If we inject the same Sentry plugin instance into both the root and worker config, and have a way to track when it is called for a worker, we can track the debugIds for workers and include them with all other chunks.
I've just realised it's not that simple because our debugID injection uses
new Error().stackto get the script URL and that wouldn't work in this case 😭Lms24 commentedon Jul 17, 2025
yes, I think this is a hard limitation for us being smarter at build time 🤔
Even if we could, I'm not sure if timing-wise, we know it early enough to inject anything into the main bundle(s) anymore 🤔 AFACT, the worker build is an isolated build, though happy to be proven wrong here :D
feat(js): Update web worker guide with new `webWorkerIntegration` APIs (
Lms24 commentedon Jul 25, 2025
@mattico once you're back: We've updated our web worker docs with the new
webWorkerIntegrationapproach. In there we now also mention that the plugin needs to be passed to Vite'sworkerbuild.I'll close this issue for now. Let us know if this should be reopened.
feat(js): Update web worker guide with new `webWorkerIntegration` APIs (