Is there an existing issue for this?
How do you use Sentry?
Self-hosted/on-premise
Which SDK are you using?
@sentry/sveltekit
SDK Version
10.47.0
Framework Version
SvelteKit 2.50.2
Link to Sentry event
No response
Reproduction Example/SDK Setup
https://github.com/dsp28/sveltekit-sentry
Steps to Reproduce
- Create a minimal SvelteKit project with
@sveltejs/adapter-node and @sentry/sveltekit:
npx sv@0.13.1 create --template minimal --types ts --add sveltekit-adapter="adapter:node" --install npm .
npm install @sentry/sveltekit@10.47.0 --save
- Set up Sentry following the SvelteKit manual setup guide, including
sentrySvelteKit() in vite.config.ts with build.sourcemap = true.
- Create a route with both a universal
load function in +page.ts and actions in +page.server.ts. Throw an error from the action:
// src/routes/+page.ts
import { redirect } from '@sveltejs/kit';
import { resolve } from '$app/paths';
import type { PageLoad } from './$types';
export const load: PageLoad = async () => {
if (Math.random() > 0.99) return redirect(303, resolve('/won'));
};
// src/routes/+page.server.ts
import type { Actions } from './$types';
export const actions: Actions = {
default: async ({ request }) => {
if (await request.formData().then(d => d.get('action') === 'throw'))
throw new Error('Sentry Test Error');
return { success: true };
},
};
- Run
npm run build and inspect the output in chunks.
More details: see reproduction repo.
Expected Result
The error thrown in +page.server.ts should be correctly source-mapped in Sentry, pointing to the original +page.server.ts file and the correct line number.
Actual Result
The error is captured but incorrectly source-mapped in Sentry.
Root cause: (as I understand it) During vite build, the sentrySvelteKit plugin injects a unique debug ID snippet into each intermediate file in output (which maps 1:1 to source files). The @sveltejs/adapter-node build stage then merges some of these files into single output chunks — for example, +page.ts and +page.server.ts are bundled together.
The resulting chunk contains two debug ID injection snippets — one from each original source file:
// First debug ID (from +page.ts)
!(function() {
try {
// ...
n && (e._sentryDebugIds = e._sentryDebugIds || {},
e._sentryDebugIds[n] = "982f403b-6069-4cb5-a799-2b9ffef9767f",
e._sentryDebugIdIdentifier = "sentry-dbid-982f403b-6069-4cb5-a799-2b9ffef9767f");
} catch (e2) {}
})();
// ... +page.ts code ...
// Second debug ID (from +page.server.ts)
!(function() {
try {
// ...
n && (e._sentryDebugIds = e._sentryDebugIds || {},
e._sentryDebugIds[n] = "983f3adb-d513-4148-9398-a76b21644b32",
e._sentryDebugIdIdentifier = "sentry-dbid-983f3adb-d513-4148-9398-a76b21644b32");
} catch (e2) {}
})();
// ... +page.server.ts code (contains the thrown error) ...
The sourcemap emitted by the adapter correctly references both original source files, but Sentry's sourcemap upload only registers the first debug ID in the file. Consequently, any error originating from code positioned after the second debug ID (i.e. +page.server.ts) cannot be correctly source-mapped.
Additional Context
No response
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.
Is there an existing issue for this?
How do you use Sentry?
Self-hosted/on-premise
Which SDK are you using?
@sentry/sveltekit
SDK Version
10.47.0
Framework Version
SvelteKit 2.50.2
Link to Sentry event
No response
Reproduction Example/SDK Setup
https://github.com/dsp28/sveltekit-sentry
Steps to Reproduce
@sveltejs/adapter-nodeand@sentry/sveltekit:sentrySvelteKit()in vite.config.ts withbuild.sourcemap = true.loadfunction in+page.tsandactionsin+page.server.ts. Throw an error from the action:npm run buildand inspect the output in chunks.More details: see reproduction repo.
Expected Result
The error thrown in
+page.server.tsshould be correctly source-mapped in Sentry, pointing to the original +page.server.ts file and the correct line number.Actual Result
The error is captured but incorrectly source-mapped in Sentry.
Root cause: (as I understand it) During
vite build, thesentrySvelteKitplugin injects a unique debug ID snippet into each intermediate file in output (which maps 1:1 to source files). The@sveltejs/adapter-nodebuild stage then merges some of these files into single output chunks — for example,+page.tsand+page.server.tsare bundled together.The resulting chunk contains two debug ID injection snippets — one from each original source file:
The sourcemap emitted by the adapter correctly references both original source files, but Sentry's sourcemap upload only registers the first debug ID in the file. Consequently, any error originating from code positioned after the second debug ID (i.e.
+page.server.ts) cannot be correctly source-mapped.Additional Context
No response
Priority
React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding
+1orme too, to help us triage it.