sveltekit-sentry Svelte Themes

Sveltekit Sentry

PoC: @sentry/sveltekit source maps break when @sveltejs/adapter-node merges files. Debug IDs are injected per-source-file before the adapter bundles them, resulting in chunks with multiple debug IDs. Sentry only registers the first, causing incorrect source mapping for errors in subsequent sections.

sveltekit-sentry

Recreate

To recreate this project with the same configuration:

npx [email protected] create --template minimal --types ts --add sveltekit-adapter="adapter:node" --install npm .
npm install @sentry/[email protected] --save

Follow instructions from https://docs.sentry.io/platforms/javascript/guides/sveltekit/manual-setup/

  • src/hooks.client.ts: configure Sentry and handleError hook for the client
  • svelte.config.js: set config.kit.experimental.instrumentation.server = true
  • src/instrumentation.server.ts: configure Sentry for the server
  • src/hooks.server.ts: configure handleError and handle hooks for the server
  • vite.config.ts: set build.sourcemap = true and configure sentrySvelteKit plugin

Set up a route with PageLoad in +page.ts and Actions in +page.server.ts. Throw an error in Actions.

Problem

The thrown error is captured but incorrectly source mapped in Sentry.

During npm run build - Sentry seems to inject debug ids after the SvelteKit build stage (.svelte-kit), which seems to emit files that map 1:1 to source files. Then the @sveltekit/adapter-node stage (build) merges some files - in this case +page.ts and +page.server.ts gets merged into a single output file. This messes up Sentry source mapping, because the merged file effectively has debug ids injected twice:

grep -rl "Sentry Test Error" build | xargs cat

Note that the sourcemap emitted by SvelteKit+adapter-node build correctly references both original source files, but the Sentry sourcemap upload only registers the first debug id in the file and thus can not correctly source map the error that originates 'under' the second debug id (in +page.server.ts). This is why I believe this to be a Sentry issue and not an issue with the SvelteKit adapter or build process.

Top categories

Loading Svelte Themes