Source Maps

To enable readable stack traces in your Sentry errors, you need to upload your source maps to Sentry.

Upload Source Maps for a Svelte Project

This page is a guide on how to create releases and upload source maps to Sentry when bundling your Svelte app.

To generate source maps with your Svelte project, you need to set the source map compiler options in your Svelte config:

svelte.config.js
Copied
import sveltePreprocess from "svelte-preprocess";

const config = {
  compilerOptions: {
    enableSourcemap: true,
  },
  preprocess: sveltePreprocess({
    sourceMap: true,
  }),
};

export default config;

If you're using Vite in you Svelte project, you can use Sentry's Vite plugin for convenience:

Copied
npm install @sentry/vite-plugin --save-dev

Configure Vite to emit source maps and use the Sentry Vite plugin:

vite.config.js
Copied
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { sentryVitePlugin } from "@sentry/vite-plugin";

export default defineConfig({
  build: {
    sourcemap: true, // Source map generation must be turned on
  },
  plugins: [
    svelte(),

    // Put the Sentry vite plugin after all other plugins
    sentryVitePlugin({
      org: "example-org",
      project: "example-project",

      // Auth tokens can be obtained from https://sentry.io/settings/account/api/auth-tokens/
      // and need `project:releases` and `org:read` scopes
      authToken: process.env.SENTRY_AUTH_TOKEN,

      sourcemaps: {
        // Specify the directory containing build artifacts
        assets: "./dist/**",
      },

      // Use the following option if you're on an SDK version lower than 7.47.0:
      // include: "./dist",

      // Optionally uncomment the line below to override automatic release name detection
      // release: process.env.RELEASE,
    }),
  ],
});

Other Bundlers

If you're using a bundler other than Vite, check out our general guide on how to upload source maps, or refer to your bundler's documentation.

Additional Resources

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) to suggesting an update ("yeah, this would be better").