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.

By default, sentrySvelteKit() will add an instance of the Sentry Vite Plugin, to upload source maps for both server and client builds. This means that when you run a production build (npm run build), source maps will be generated and uploaded to Sentry so that you get readable stack traces in your Sentry issues.

However, you still need to specify your Sentry auth token as well as your org and project slugs. There are two ways to set them:

Option 1

You can set them as environment variables, for example, in a .env file:

  • SENTRY_ORG your Sentry org slug
  • SENTRY_PROJECT your Sentry project slug
  • SENTRY_AUTH_TOKEN your Sentry auth token (can be obtained from the Organization Token Settings)
  • SENTRY_URL your Sentry instance URL. This is only required if you use your own Sentry instance (as opposed to https://sentry.io).

Option 2:

You can also set them by passing a sourceMapsUploadOptions object to sentrySvelteKit, as seen in the example below. For a full list of available options, see the Sentry Vite Plugin documentation.

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

export default {
  plugins: [
sentrySvelteKit({ sourceMapsUploadOptions: { org: "example-org", project: "example-project", authToken: "sntrys_YOUR_TOKEN_HERE", // If you're self-hosting Sentry, also add your instance URL: // url: "https://your-self-hosted-sentry.com/",
}, }), sveltekit(), ], // ... rest of your Vite config };

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 by passing the adapter option to sentrySvelteKit:

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

export default {
  plugins: [
    sentrySvelteKit({
adapter: "vercel",
}), sveltekit(), ], // ... rest of your Vite config };

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

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

export default {
  plugins: [
    sentrySvelteKit({
autoUploadSourceMaps: false,
}), sveltekit(), ], // ... rest of your Vite config };

If you disable automatic source maps upload, you must explicitly set a release value in your Sentry.init() configuration. This is important for Sentry features like release health and correctly associating errors with specific deployments.

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").