Repository navigation
Description
Is there an existing issue for this?
- I have checked for existing issues https://github.com/getsentry/sentry-javascript/issues
- I have reviewed the documentation https://docs.sentry.io/
- I am using the latest SDK release https://github.com/getsentry/sentry-javascript/releases
How do you use Sentry?
Sentry Saas (sentry.io)
Which SDK are you using?
@sentry/nextjs
SDK Version
11.20.0 (develop at 489a157 has the same tree)
Framework Version
Next 16.4.6 (Turbopack)
Link to Sentry event
No response
Reproduction Example/SDK Setup
The next.config.mjs the reproducer writes:
import { chmodSync, readdirSync, writeFileSync } from 'node:fs';
import { join, resolve } from 'node:path';
import { withSentryConfig } from '@sentry/nextjs/config';
const nextConfig = {
productionBrowserSourceMaps: true,
compiler: {
runAfterProductionCompile: ({ distDir, projectDir }) => {
const chunks = resolve(projectDir, distDir, 'static', 'chunks');
const maps = readdirSync(chunks).filter(name => name.endsWith('.map'));
chmodSync(chunks, 0o555);
writeFileSync(join(projectDir, 'locked-maps.json'), JSON.stringify({ chunks, maps }));
},
},
};
export default withSentryConfig(nextConfig, {
sourcemaps: { deleteSourcemapsAfterUpload: true },
telemetry: false,
});Steps to Reproduce
- Configure a Next.js app with
productionBrowserSourceMaps: trueandwithSentryConfig(nextConfig, { sourcemaps: { deleteSourcemapsAfterUpload: true } }). - Make the client source maps undeletable before the SDK deletes them. The config above does it in its own
compiler.runAfterProductionCompilehook, which runs right before the SDK's, by making.next/static/chunksread-only. - Run
next build.
The gist runs these steps: clone it and run node repro.mjs on Linux or macOS as a user other than root (my run: docker run --rm -u node -v ./:/gist:ro -w /tmp node:26.12.1 node /gist/repro.mjs in the clone). It installs [email protected] and the latest @sentry/nextjs in a new temporary folder, builds with no auth token (nothing is uploaded; the SDK deletes the maps all the same), and counts how many of the maps the hook locked are still in .next/static/chunks after the build. It exits 0 when the build output names a map it could not delete, 1 when the maps stay and the output names none of them, 2 when a step fails. node repro.mjs file:/abs/sentry-nextjs.tgz @sentry/bundler-plugins=file:/abs/sentry-bundler-plugins.tgz runs packages packed from a checkout.
Expected Result
The build reports each source map it could not delete as an error and fails by default, as deleteFromOutput in the same file does when the same fs.promises.rm fails (
sentry-javascript/packages/bundler-plugins/src/core/build-plugin-manager.ts
Lines 982 to 1000 in 489a157
| async deleteFromOutput(sourceMapPaths) { | |
| try { | |
| await Promise.all( | |
| sourceMapPaths.map(async sourceMapPath => { | |
| try { | |
| await fs.promises.rm(sourceMapPath, { force: true }); | |
| } catch (e) { | |
| logger.error(`Could not delete source map ${sourceMapPath} from the build output.`); | |
| throw e; | |
| } | |
| }), | |
| ); | |
| } catch (e) { | |
| sentryScope.captureException('Error deleting source maps after upload'); | |
| await safeFlushTelemetry(sentryClient); | |
| // Throwing by default: a map left in the output could leak to production. | |
| handleRecoverableError(e, true); | |
| } | |
| }, |
{ force: true } lets it, and an errorHandler in the options still decides whether the build fails.
Actual Result
next build exits 0, every map stays in .next/static/chunks, and nothing in the output says so:
node v26.12.1, linux x64, uid 1000
1. npm install @sentry/nextjs@latest [email protected] [email protected] [email protected]
installed: @sentry/nextjs 11.20.0, @sentry/bundler-plugins 11.20.0, next 16.4.6, react 19.3.1
2. next build (productionBrowserSourceMaps: true; withSentryConfig with sourcemaps.deleteSourcemapsAfterUpload: true; the app's runAfterProductionCompile hook makes .next/static/chunks read-only before @sentry/nextjs deletes its source maps)
next build exited 0
the hook made .next/static/chunks read-only, with 7 source maps in it: 0xvgwj92hbc31.js.map, 131kgzbuq92zu.js.map, 1jibdzavc374r.js.map, 1z_gsvi_wtuoo.js.map, 24rwc4j2i6_n6.js.map, 2gwr7q9afrpqd.js.map, 3zalnv52zv1-9.js.map
@sentry/nextjs lines in the build output:
[@sentry/nextjs - After Production Compile] Warning: No auth token provided. Will not upload source maps. Please set the `authToken` option. You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/
build output lines naming one of those maps: none
3. .next/static/chunks after the build: 7 of 7 source maps still there
Summary: @sentry/nextjs 11.20.0, @sentry/bundler-plugins 11.20.0, next 16.4.6, react 19.3.1. next build exited 0; 7 of 7 source maps stayed in .next/static/chunks, and the build output names none of them. Exit 1.
deleteArtifacts, which @sentry/nextjs calls after the upload (
| await sentryBuildPluginManager.deleteArtifacts(); |
fs.promises.rm and logs it with logger.debug (sentry-javascript/packages/bundler-plugins/src/core/build-plugin-manager.ts
Lines 1020 to 1027 in 489a157
| await Promise.all( | |
| filePathsToDelete.map(filePathToDelete => | |
| fs.promises.rm(filePathToDelete, { force: true }).catch(e => { | |
| // This is allowed to fail - we just don't do anything | |
| logger.debug(`An error occurred while attempting to delete asset: ${filePathToDelete}`, e); | |
| }), | |
| ), | |
| ); |
try and handleRecoverableError never see the failure.
Additional Context
That .catch came in with getsentry/sentry-javascript-bundler-plugins#373, for an ENOENT that failed the build (getsentry/sentry-javascript-bundler-plugins#370); it catches every other error the same way.
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding +1 or me too, to help us triage it.
Metadata
Metadata
Assignees
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Nov 28, 2026
JS-4178
timfish commentedon Nov 28, 2026
The reproduction for this issue is completely synthetic and the issue description is a huge wall of text that doesn't clearly describe what the actual issue is.
Why would sourcemaps not be deletable? How does this reproduce in regular usage?
Also
deleteSourcemapsAfterUploadis about to be deprecated. Does this issue also apply to the newsourcemaps: { delete: true }?