Skip to content

feat(bundler-plugins): Enable external source maps and delete them after upload in the esbuild plugin - #25648

Open
timfish wants to merge 1 commit into
feat/bundler-plugins-delete-sourcemaps-webpackfrom
feat/bundler-plugins-delete-sourcemaps-esbuild
Open

timfish wants to merge 1 commit into
feat/bundler-plugins-delete-sourcemaps-webpackfrom
feat/bundler-plugins-delete-sourcemaps-esbuild

Conversation

@timfish

@timfish timfish commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Part of the stack for #25609. esbuild writes its output before onEnd runs and has no hook to drop an output, so the plugin sets sourcemap: 'external' when the setting is unset and deletes the maps after a successful upload: every map in the metafile when the plugin turned them on, and exactly the maps the upload read from disk when the user enabled them, which uploadSourcemaps now reports. When the upload fails all maps stay, with an error log. With write: false the setting is left alone, because nothing reaches the disk.

The metafile lists outputs relative to absWorkingDir, while the upload globbed them from the process working directory, so builds with an absWorkingDir elsewhere uploaded nothing. The paths are now resolved against absWorkingDir first, and passed with forward slashes because glob reads backslashes as escapes. Integration fixtures cover ignore and assets on the staged path for esbuild.

@timfish
timfish added this pull request to stack #25649 October 22, 2026 10:47
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 7d21eb9 (PR test merge using develop at 41ac03e)

Against: 4d85171 (develop) · base run #64969

⚠️ Baseline mismatch: 6 develop commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once develop's baseline build for 41ac03e finishes.

Path Size % Change Change
@sentry/browser 30.4 kB - -
@sentry/browser - with treeshaking flags 28.54 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.43 kB - -
@sentry/browser (incl. Tracing) 52.72 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.72 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.69 kB - -
@sentry/browser (incl. Tracing, Replay) 93.02 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.76 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.75 kB - -
@sentry/browser (incl. Feedback) 47.98 kB - -
@sentry/browser (incl. sendFeedback) 35.5 kB - -
@sentry/browser (incl. FeedbackAsync) 40.61 kB - -
@sentry/browser (incl. Metrics) 31.44 kB - -
@sentry/browser (incl. Logs) 31.73 kB - -
@sentry/browser (incl. Metrics & Logs) 32.45 kB - -
@sentry/react 32.29 kB - -
@sentry/react (incl. Tracing) 55.09 kB - -
@sentry/vue 38.67 kB - -
@sentry/vue (incl. Tracing) 55.73 kB - -
@sentry/svelte 30.43 kB - -
@sentry/remix (Remix 3 client bundle) 57.8 kB - -
CDN Bundle 32.19 kB - -
CDN Bundle (incl. Tracing) 53.24 kB - -
CDN Bundle (incl. Logs, Metrics) 34.47 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.19 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.88 kB - -
CDN Bundle (incl. Tracing, Replay) 91.46 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.39 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.56 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.56 kB - -
CDN Bundle - uncompressed 94.67 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.63 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 101.14 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 163.37 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.71 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 279.32 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 285.05 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 293.03 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 298.74 kB - -
@sentry/nextjs (client) 58.04 kB - -
@sentry/sveltekit (client) 53.23 kB - -
@sentry/core/server 44.25 kB - -
@sentry/core/browser 13.93 kB - -
@sentry/node 155.68 kB +0.02% +21 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 82.26 kB - -
@sentry/node - without tracing 96.89 kB +0.02% +15 B 🔺
@sentry/node - without channel injection 136 kB +0.02% +21 B 🔺
@sentry/aws-serverless 105.11 kB +0.02% +19 B 🔺
@sentry/cloudflare (withSentry) - minified 200.67 kB - -
@sentry/cloudflare (withSentry) 499.05 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 221.22 kB - -

View base workflow run

@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 0d05fc7 to 73fee34 Compare October 22, 2026 10:57
@github-actions

github-actions Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 4 not successful, 49 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Failing after 16s Details
❌ CI: Optional E2E Tests / E2E nuxt-5 (tunnel-dev) Test (optional) Failing after 24s Details
❌ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Failing after 14s Details
❌ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Failing after 13s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 29s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 47s Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 19s Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 17s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 30s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 29s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 16s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 24s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 50s Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 19s Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 (tracer provider) Test (optional) Successful in 23s Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 38s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 59s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 40s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 21s Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 19s Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (deno) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 26s Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 22s Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 1m Details

@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 73fee34 to 4040760 Compare October 22, 2026 11:13
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch 2 times, most recently from 3885821 to 62b848d Compare October 27, 2026 16:25
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 62b848d to f5d5367 Compare October 27, 2026 16:32
@timfish
timfish marked this pull request as ready for review October 27, 2026 18:02

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from f5d5367 to ba5d8ca Compare October 28, 2026 12:15
@timfish
timfish requested review from a team as code owners October 28, 2026 12:15
@timfish
timfish requested review from isaacs, logaretm, msonnb, mydea and nicohrubec and removed request for a team October 28, 2026 12:15
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from ba5d8ca to 6f13518 Compare October 28, 2026 12:33

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 2b44493 to 71c0775 Compare October 29, 2026 17:39
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 71c0775 to 0edb347 Compare October 29, 2026 17:43
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 0edb347 to 5c128dc Compare October 29, 2026 20:54
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 5c128dc to 8d8e755 Compare October 29, 2026 21:36
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 8d8e755 to 2b9c8fe Compare October 29, 2026 21:59
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch 3 times, most recently from d661b73 to 2854a5a Compare October 30, 2026 12:46
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 2854a5a to d8075e3 Compare October 30, 2026 15:05
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from d8075e3 to 35e806c Compare October 30, 2026 15:22
@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 35e806c to 84a11f9 Compare October 30, 2026 15:57

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

@timfish
timfish force-pushed the feat/bundler-plugins-delete-sourcemaps-esbuild branch from 84a11f9 to 6f443bc Compare October 30, 2026 16:17
stacked auto-merge was automatically disabled November 3, 2026 10:28

Pull Request is not mergeable

@isaacs isaacs left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

esbuild offers no way to drop an output before it is written, so turning on external maps and deleting them after a successful upload is the only practical approach. Keeping maps when the upload fails is the safe default for maps the user asked for. The absWorkingDir path fix is a real improvement on its own.

The weak point is that the delete step guesses what was uploaded instead of being told. It also follows "delete only what was uploaded" even for maps the plugin created itself . In esbuild, where only entry points carry debug IDs, that guess leaves maps behind for shared chunks, lazy chunks and CSS, and leaves all maps behind on rebuilds (made visible by an older bug).

Have the upload report what it sent, delete all plugin-created maps on the unset path, and clear the wrapped-path set per build. With those changes, the esbuild plugin matches what the changelog says.

if (hasDebugId(code)) {
uploaded.push(`${artifact}.map`);
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: when the decision came from kind === 'unset', the user never asked for any maps. After a successful upload, delete every .map in the metafile outputs, not just the uploaded ones. For maps the user enabled (deleteSourcemapsAfterUpload: true), keep the current rule of deleting only uploaded maps. Shared and lazy chunks without debug IDs are a separate, older gap. Could track it as follow-up work, since those chunks can't be symbolicated either way.

// afterwards instead of being dropped from the output like in other bundlers.
if (sourceMapDecision.deleteAfterUpload && initialOptions.write !== false) {
const { shouldUpload } = sentryBuildPluginManager.sourceMaps;
const sourceMaps = await getUploadedSourceMaps(buildArtifacts, shouldUpload);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The delete list is calculated separately from what actually gets sent.

getUploadedSourceMaps rebuilds the upload's choices: isJsFile, a sibling .map in the metafile, shouldUpload, and hasDebugId. The upload makes its own choices with globFiles(assets ?? artifacts, { ignore }) and then prepareBundleForDebugIdUpload, which can skip a chunk (no map found by the resolveSourceMap hook, read error, and so on). upload() only returns one uploaded flag for the whole run. Wherever the two disagree, the plugin deletes a map that was never uploaded, and that copy is gone.

Suggestion: have upload() return the chunk paths it actually prepared and uploaded (it already has debugIdChunkFilePaths and the per-chunk results). Delete exactly the maps of those chunks. This removes getUploadedSourceMaps, hasDebugId and the extra file reads, and makes the deletion safe by construction.

if (uploaded) {
await Promise.all(sourceMaps.map(sourceMap => fs.promises.rm(sourceMap, { force: true })));
} else if (sourceMaps.length > 0) {
logger.error('The source maps were not uploaded, so they stay in the build output.');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On rebuilds (context().rebuild(), watch mode) the default path leaves maps. Reproduced with esbuild.context() and two rebuild() calls:

  • First rebuild: entry maps uploaded and deleted, as intended.
  • Second rebuild: e1.js has no debug ID. The upload warns "No source maps found for any of the 4 matched build artifacts", and e1.js.map and e2.js.map stay in the output. The "source maps were not uploaded" error does not fire, because getUploadedSourceMaps finds no debug IDs and returns an empty list.

The debug ID loss is older than this PR. debugIdWrappedPaths is cleared in setup() (line 220), which runs once per context, not per build, so on a rebuild the onResolve hook skips every entry point as "already wrapped". I got the same "No source maps found" warning with an explicit sourcemap: 'external', so the upload regression is not new. What this PR adds is that the plugin now turns maps on for these builds and then leaves them on disk with no error.

Suggestion: clear debugIdWrappedPaths in an onStart hook instead of setup(). That fixes rebuild uploads and this PR's cleanup together. It is a one-line fix that could also go in its own fix(bundler-plugins) PR. A context().rebuild() test would catch this.

});
}

const sourceMapDecision = sentryBuildPluginManager.sourceMaps.decide(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With write: false, the plugin turns on maps it can never upload, and logs a false message.

The upload reads the metafile paths from disk. With write: false nothing is on disk, so nothing can be uploaded. The plugin still sets sourcemap: 'external', so callers that handle outputFiles themselves now get .map entries they never asked for. decide() also logs "Enabling hidden source maps. They are uploaded to Sentry and removed from the build output." at setup time, which is false here. This is the same problem #25645 fixed for Rollup's generate().

Suggestion: when initialOptions.write === false, skip the decision (or call decide(kind, { log: false }) and don't set sourcemap).

if (options.sourcemaps?.disable !== 'disable-upload') {
await upload(buildArtifacts);
// The upload globs the paths, and glob reads backslashes as escapes.
const { uploaded } = await upload(buildArtifacts.map(artifact => artifact.split(path.sep).join('/')));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm not sure why Bugbot resolved this, I think they're still globs? Shouldn't they get escaped with eg glob.escape() to ensure there's no * or ? chars to mess things up? Eg, what'd happen with a path like widget[id].js or something?

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

…ter upload in the esbuild plugin

esbuild writes its output before `onEnd` runs and has no hook to drop
an output, so the maps are deleted from disk after a successful upload
instead. When the upload fails they stay, with an error log.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ecad382. Configure here.

await Promise.all(sourceMaps.map(sourceMap => fs.promises.rm(sourceMap, { force: true })));
} else if (sourceMaps.length > 0) {
logger.error('The source maps were not uploaded, so they stay in the build output.');
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rebuilds leave generated source maps

Medium Severity

On incremental rebuilds the plugin still emits the external maps it turned on, but those rebuilds do not carry debug IDs, so upload reports a failure and the maps remain in the output. Users who never enabled source maps then get map files left on disk after the first rebuild() or watch pass.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit ecad382. Configure here.

This branch has not been deployed

No deployments
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.

2 participants