-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
@sentry/sveltekit: Incorrect source mapping when adapter-node merges files containing multiple injected debug IDs #20084
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?
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-nodeand@sentry/sveltekit:npx [email protected] create --template minimal --types ts --add sveltekit-adapter="adapter:node" --install npm . npm install @sentry/[email protected] --save
- Set up Sentry following the SvelteKit manual setup guide, including
sentrySvelteKit()in vite.config.ts withbuild.sourcemap = true. - Create a route with both a universal
loadfunction in+page.tsandactionsin+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 buildand 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.
Metadata
Metadata
Assignees
Fields
Give feedbackProjects
Status