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, the sentrySvelteKit() Vite plugin uploads 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 all values as environment variables, for example, in a .env file:

.env
Copied
# DO NOT commit this file to your repo. The auth token is a secret.
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE
SENTRY_ORG=example-org
SENTRY_PROJECT=example-project
# SENTRY_URL is only necessary if you're using a self-hosted Sentry
# instance (as opposed to `https://sentry.io`)
SENTRY_URL="https://your-sentry-instance.com"

Option 2

You can also set your org and project slugs 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: process.env.SENTRY_AUTH_TOKEN, // If you're self-hosting Sentry, also add your instance URL: // url: "https://your-self-hosted-sentry.com/",
}, }), sveltekit(), ], // ... rest of your Vite config };

To keep your auth token secure, always store it in an environment variable instead of directly in your files:

.env
Copied
SENTRY_AUTH_TOKEN=sntrys_YOUR_TOKEN_HERE

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