Source Maps

Upload your source maps to Sentry to enable readable stack traces in your errors, along with numerous other benefits. Learn more here.

@sentry/sveltekit will generate and upload source maps automatically, so that errors in Sentry will contain readable stack traces.

The SvelteKit SDK uses the Sentry Vite Plugin to upload source maps. See the Sentry Vite Plugin documentation for all available options.

@sentry/sveltekit will generate and upload source maps automatically during production builds, so that errors in Sentry contain readable stack traces.

The easiest way to configure uploading source maps is by using the Sentry Wizard.

Copied
npx @sentry/wizard@latest -i sveltekit

Note: Source maps are only generated and uploaded during production builds (npm run build). Development builds (npm run dev) do not generate source maps for upload.

See how uploading source maps lets you see the exact line of code that caused an error:

If you installed the SDK manually or the wizard failed, follow the steps below to manually configure source maps upload.

To automatically upload source maps, you need to provide your Sentry auth token, organization, and project slugs in your Vite configuration:

Make sure you add your auth token to your CI, if you are using one to deploy your application.

Add your auth token to your environment:

.env
Copied
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE

Configure source map behavior using the source maps options in your Vite config:

vite.config.js
Copied
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      sourceMapsUploadOptions: {
        org: "example-org",
        project: "example-project",
        authToken: process.env.SENTRY_AUTH_TOKEN,
        sourcemaps: {
          assets: ["./build/*/**/*"],
          ignore: ["**/build/client/**/*"],
          filesToDeleteAfterUpload: ["./build/**/*.map"],
        },
      },
    }),
    sveltekit(),
  ],
});

By default, sentrySvelteKit will try to detect your SvelteKit adapter to configure the source maps upload correctly. If you're not using one of the supported adapters or the wrong one is detected, you can override the adapter detection:

vite.config.js
Copied
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      adapter: "vercel",
    }),
    sveltekit(),
  ],
});

You can disable automatic source maps upload in your Vite config:

vite.config.js
Copied
import { sveltekit } from "@sveltejs/kit/vite";
import { sentrySvelteKit } from "@sentry/sveltekit";

export default defineConfig({
  plugins: [
    sentrySvelteKit({
      autoUploadSourceMaps: false,
    }),
    sveltekit(),
  ],
});

If you're experiencing issues with source maps, see Troubleshooting Source Maps.

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